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
;;
132 let selfexec = ref "";;
135 if platform = Pcygwin
137 let sh = "/bin/sh" in
138 let args = [|sh; "-c"; cmd
|] in
139 let rec std si so se
= function
141 | (fd
, 0) :: rest
-> std fd so se rest
142 | (fd
, -1) :: rest
->
143 Unix.set_close_on_exec fd
;
146 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
148 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
149 ignore
(Unix.create_process
sh args si so se
)
154 type mpos
= int * int
156 | Msel
of (mpos
* mpos
)
158 | Mscrolly
| Mscrollx
159 | Mzoom
of (int * int)
160 | Mzoomrect
of (mpos
* mpos
)
164 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
165 and onkey
= string -> int -> te
166 and ondone
= string -> unit
167 and histcancel
= unit -> unit
168 and onhist
= ((histcmd
-> string) * histcancel
)
169 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
170 and cancelonempty
= bool
175 | TEswitch
of textentry
186 let bound v minv maxv
=
187 max minv
(min maxv v
);
191 { store
= Array.create n v
198 let cbcap b
= Array.length b
.store
;;
203 b
.wc
<- (b
.wc
+ 1) mod cap;
205 b
.len
<- min
(b
.len
+ 1) cap;
208 let cbempty b
= b
.len
= 0;;
210 let cbgetg b circular dir
=
214 let rc = b
.rc + dir
in
226 else bound rc 0 (b
.len
-1)
232 let cbget b
= cbgetg b
false;;
233 let cbgetc b
= cbgetg b
true;;
235 let drawstring size x y s
=
237 Gl.enable `texture_2d
;
238 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
239 ignore
(drawstr size x y s
);
241 Gl.disable `texture_2d
;
244 let drawstring1 size x y s
=
248 let drawstring2 size x y fmt
=
249 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
268 dolog
"l %d dim=%d {" l
.pageno l
.pagedimno
;
269 dolog
" WxH %dx%d" l
.pagew l
.pageh
;
270 dolog
" vWxH %dx%d" l
.pagevw l
.pagevh
;
271 dolog
" pagex,y %d,%d" l
.pagex l
.pagey
;
272 dolog
" dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
273 dolog
" column %d" l
.pagecol
;
277 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
279 dolog
" x0,y0=(% f, % f)" x0 y0
;
280 dolog
" x1,y1=(% f, % f)" x1 y1
;
281 dolog
" x2,y2=(% f, % f)" x2 y2
;
282 dolog
" x3,y3=(% f, % f)" x3 y3
;
286 type multicolumns
= multicol
* pagegeom
287 and singlecolumn
= pagegeom
288 and splitcolumns
= columncount
* pagegeom
289 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
290 and multicol
= columncount
* covercount
* covercount
292 and columncount
= int
293 and covercount
= int;;
300 { mutable scrollbw
: int
301 ; mutable scrollh
: int
302 ; mutable scrollb
: scrollb
303 ; mutable icase
: bool
304 ; mutable preload
: bool
305 ; mutable pagebias
: int
306 ; mutable verbose
: bool
307 ; mutable debug
: bool
308 ; mutable scrollstep
: int
309 ; mutable hscrollstep
: int
310 ; mutable maxhfit
: bool
311 ; mutable crophack
: bool
312 ; mutable autoscrollstep
: int
313 ; mutable maxwait
: float option
314 ; mutable hlinks
: bool
315 ; mutable underinfo
: bool
316 ; mutable interpagespace
: interpagespace
317 ; mutable zoom
: float
318 ; mutable presentation
: bool
319 ; mutable angle
: angle
320 ; mutable cwinw
: int
321 ; mutable cwinh
: int
322 ; mutable savebmarks
: bool
323 ; mutable fitmodel
: fitmodel
324 ; mutable trimmargins
: trimmargins
325 ; mutable trimfuzz
: irect
326 ; mutable memlimit
: memsize
327 ; mutable texcount
: texcount
328 ; mutable sliceheight
: sliceheight
329 ; mutable thumbw
: width
330 ; mutable jumpback
: bool
331 ; mutable bgcolor
: (float * float * float)
332 ; mutable bedefault
: bool
333 ; mutable tilew
: int
334 ; mutable tileh
: int
335 ; mutable mustoresize
: memsize
336 ; mutable checkers
: bool
337 ; mutable aalevel
: int
338 ; mutable urilauncher
: string
339 ; mutable pathlauncher
: string
340 ; mutable colorspace
: colorspace
341 ; mutable invert
: bool
342 ; mutable colorscale
: float
343 ; mutable redirectstderr
: bool
344 ; mutable ghyllscroll
: (int * int * int) option
345 ; mutable columns
: columns
346 ; mutable beyecolumns
: columncount
option
347 ; mutable selcmd
: string
348 ; mutable updatecurs
: bool
349 ; mutable keyhashes
: (string * keyhash
) list
350 ; mutable hfsize
: int
351 ; mutable pgscale
: float
352 ; mutable usepbo
: bool
353 ; mutable wheelbypage
: bool
354 ; mutable stcmd
: string
355 ; mutable riani
: bool
358 | Csingle
of singlecolumn
359 | Cmulti
of multicolumns
360 | Csplit
of splitcolumns
363 type anchor
= pageno
* top
* dtop
;;
365 type outline
= string * int * anchor
;;
367 type rect
= float * float * float * float * float * float * float * float;;
369 type tile
= opaque
* pixmapsize
* elapsed
370 and elapsed
= float;;
371 type pagemapkey
= pageno
* gen
;;
372 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
376 let emptyanchor = (0, 0.0, 0.0);;
378 type infochange
= | Memused
| Docinfo
| Pdim
;;
380 class type uioh
= object
381 method display
: unit
382 method key
: int -> int -> uioh
383 method button
: int -> bool -> int -> int -> int -> uioh
384 method motion
: int -> int -> uioh
385 method pmotion
: int -> int -> uioh
386 method infochanged
: infochange
-> unit
387 method scrollpw
: (int * float * float)
388 method scrollph
: (int * float * float)
389 method modehash
: keyhash
390 method eformsgs
: bool
394 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
395 | Textentry
of (textentry
* onleave
)
397 | LinkNav
of linktarget
398 and onleave
= leavetextentrystatus
-> unit
399 and leavetextentrystatus
= | Cancel
| Confirm
400 and helpitem
= string * int * action
403 | Action
of (uioh
-> uioh
)
405 | Ltexact
of (pageno
* int)
409 let isbirdseye = function Birdseye _
-> true | _
-> false;;
410 let istextentry = function Textentry _
-> true | _
-> false;;
414 | Loading
of (page
* gen
)
416 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
418 | Outlining
of outline list
421 let emptykeyhash = Hashtbl.create
0;;
422 let nouioh : uioh
= object (self
)
424 method key _ _
= self
425 method button _ _ _ _ _
= self
426 method motion _ _
= self
427 method pmotion _ _
= self
428 method infochanged _
= ()
429 method scrollpw
= (0, nan
, nan
)
430 method scrollph
= (0, nan
, nan
)
431 method modehash
= emptykeyhash
432 method eformsgs
= false
436 { mutable sr
: Unix.file_descr
437 ; mutable sw
: Unix.file_descr
438 ; mutable wsfd
: Unix.file_descr
439 ; mutable errfd
: Unix.file_descr
option
440 ; mutable stderr
: Unix.file_descr
441 ; mutable errmsgs
: Buffer.t
442 ; mutable newerrmsgs
: bool
446 ; mutable anchor
: anchor
447 ; mutable ranchors
: (string * string * anchor
* string) list
449 ; mutable layout
: page list
450 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
451 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
452 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
453 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
454 ; mutable pagecount
: int
455 ; mutable currently
: currently
456 ; mutable mstate
: mstate
457 ; mutable searchpattern
: string
458 ; mutable rects
: (pageno
* recttype
* rect
) list
459 ; mutable rects1
: (pageno
* recttype
* rect
) list
460 ; mutable text
: string
461 ; mutable winstate
: Wsi.winstate list
462 ; mutable mode
: mode
463 ; mutable uioh
: uioh
464 ; mutable outlines
: outline array
465 ; mutable bookmarks
: outline list
466 ; mutable path
: string
467 ; mutable password
: string
468 ; mutable nameddest
: string
469 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
470 ; mutable memused
: memsize
472 ; mutable throttle
: (page list
* int * float) option
473 ; mutable autoscroll
: int option
474 ; mutable ghyll
: (int option -> unit)
475 ; mutable help
: helpitem array
476 ; mutable docinfo
: (int * string) list
477 ; mutable texid
: GlTex.texture_id
option
479 ; mutable prevzoom
: float
480 ; mutable progress
: float
481 ; mutable redisplay
: bool
482 ; mutable mpos
: mpos
483 ; mutable keystate
: keystate
484 ; mutable glinks
: bool
485 ; mutable prevcolumns
: (columns
* float) option
488 ; mutable reprf
: (unit -> unit)
489 ; mutable origin
: string
492 { pat
: string circbuf
493 ; pag
: string circbuf
494 ; nav
: anchor circbuf
495 ; sel
: string circbuf
502 ; scrollb
= scrollbhv lor scrollbvv
518 ; presentation
= false
523 ; fitmodel
= FitProportional
524 ; trimmargins
= false
525 ; trimfuzz
= (0,0,0,0)
526 ; memlimit
= 32 lsl 20
531 ; bgcolor
= (0.5, 0.5, 0.5)
535 ; mustoresize
= 256 lsl 20
540 | Plinux
| Pfreebsd
| Pdragonflybsd
541 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
542 | Posx
-> "open \"%s\""
543 | Pcygwin
-> "cygstart \"%s\""
544 | Punknown
-> "echo %s")
545 ; pathlauncher
= "lp \"%s\""
548 | Plinux
| Pfreebsd
| Pdragonflybsd
549 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
556 ; redirectstderr
= false
558 ; columns
= Csingle
[||]
564 ; wheelbypage
= false
565 ; stcmd
= "echo SyncTex"
568 let mk n
= (n
, Hashtbl.create
1) in
582 let wtmode = ref false;;
584 let findkeyhash c name
=
585 try List.assoc name c
.keyhashes
586 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
589 let conf = { defconf with angle
= defconf.angle
};;
591 let pgscale h
= truncate
(float h
*. conf.pgscale);;
594 { mutable fontsize
: int
595 ; mutable wwidth
: float
596 ; mutable maxrows
: int
608 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
609 let len = String.length s
in
610 if colonpos >= 0 && colonpos + 3 < len
612 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
615 try String.rindex_from s
colonpos ' '
619 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
622 | "http" | "ftp" | "mailto" ->
624 try String.index_from s
colonpos ' '
625 with Not_found
-> len
627 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
635 if String.length
conf.urilauncher
= 0
636 then print_endline uri
638 let url = geturl uri
in
639 if String.length
url = 0
640 then Printf.eprintf
"obtained empty url from uri %S" uri
642 let re = Str.regexp
"%s" in
643 let command = Str.global_replace
re url conf.urilauncher
in
647 "failed to execute `%s': %s\n" command (exntos exn
);
653 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
654 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
658 let strings = version () :: "" :: Help.keys
in
661 let url = geturl s
in
662 if String.length
url > 0
663 then (s
, 0, Action
(fun u
-> gotouri url; u
))
664 else (s
, 0, Noaction
)
669 let firstgeomcmds = "", [];;
670 let noreprf () = ();;
677 ; stderr
= Unix.stderr
678 ; errmsgs
= Buffer.create
0
683 ; anchor
= emptyanchor
687 ; tilelru
= Queue.create
()
688 ; pagemap
= Hashtbl.create
10
689 ; tilemap
= Hashtbl.create
10
705 ; geomcmds
= firstgeomcmds
707 { nav
= cbnew 10 emptyanchor
736 if (conf.scrollb
land scrollbhv = 0)
737 || (state.x
= 0 && state.w
<= state.winw
- conf.scrollbw
)
743 if (conf.scrollb
land scrollbvv = 0)
748 let wadjsb w
= w
- vscrollw ();;
751 fstate.fontsize
<- n
;
752 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
753 fstate.maxrows
<- (state.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
759 Printf.kprintf prerr_endline fmt
761 Printf.kprintf ignore fmt
765 if String.length
conf.pathlauncher
= 0
766 then print_endline
state.path
768 let re = Str.regexp
"%s" in
769 let command = Str.global_replace
re state.path
conf.pathlauncher
in
772 Printf.eprintf
"failed to execute `%s': %s\n" command (exntos exn
);
778 type 'a t
= | Res
of 'a
| Exn
of exn
;;
781 try Res
(Unix.pipe ())
786 try tempfailureretry
Unix.close fd
787 with exn
-> f
(exntos exn
)
791 try Res
(tempfailureretry
Unix.dup fd
)
796 try Res
(tempfailureretry
(Unix.dup2 fd1
) fd2
)
801 let redirectstderr () =
802 let clofail what errmsg
= dolog
"failed to close %s: %s" what errmsg
in
803 if conf.redirectstderr
805 match Ne.pipe () with
807 dolog
"failed to create stderr redirection pipes: %s" (exntos exn
)
810 begin match Ne.dup Unix.stderr
with
812 dolog
"failed to dup stderr: %s" (exntos exn
);
813 Ne.clo r
(clofail "pipe/r");
814 Ne.clo w
(clofail "pipe/w");
816 | Ne.Res dupstderr
->
817 begin match Ne.dup2 w
Unix.stderr
with
819 dolog
"failed to dup2 to stderr: %s" (exntos exn
);
820 Ne.clo dupstderr
(clofail "stderr duplicate");
821 Ne.clo r
(clofail "redir pipe/r");
822 Ne.clo w
(clofail "redir pipe/w");
825 state.stderr
<- dupstderr
;
826 state.errfd
<- Some r
;
830 state.newerrmsgs
<- false;
831 begin match state.errfd
with
833 begin match Ne.dup2 state.stderr
Unix.stderr
with
835 dolog
"failed to dup2 original stderr: %s" (exntos exn
)
837 Ne.clo fd
(clofail "dup of stderr");
842 prerr_string
(Buffer.contents
state.errmsgs
);
844 Buffer.clear
state.errmsgs
;
850 let postRedisplay who
=
852 then prerr_endline
("redisplay for " ^ who
);
853 state.redisplay
<- true;
857 let getopaque pageno
=
858 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
859 with Not_found
-> None
862 let putopaque pageno opaque
=
863 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
866 let pagetranslatepoint l x y
=
867 let dy = y
- l
.pagedispy
in
868 let y = dy + l
.pagey
in
869 let dx = x
- l
.pagedispx
in
870 let x = dx + l
.pagex
in
874 let onppundermouse g
x y d
=
877 begin match getopaque l
.pageno
with
879 let x0 = l
.pagedispx
in
880 let x1 = x0 + l
.pagevw
in
881 let y0 = l
.pagedispy
in
882 let y1 = y0 + l
.pagevh
in
883 if y >= y0 && y <= y1 && x >= x0 && x <= x1
885 let px, py
= pagetranslatepoint l
x y in
886 match g opaque l
px py
with
899 let g opaque _
px py
=
900 match whatsunder opaque
px py
with
902 | under
-> Some under
904 onppundermouse g x y Unone
909 match unproject opaque
x y with
910 | Some
(x, y) -> Some
(Some
(l
.pageno
, x, y))
913 onppundermouse g x y None
;
917 state.text
<- Printf.sprintf
"%c%s" c s
;
918 G.postRedisplay "showtext";
922 match Ne.pipe () with
924 showtext '
!'
(Printf.sprintf
"pipe failed: %s" (exntos exn
))
927 try popen conf.selcmd
[r
, 0; w
, -1]; true
930 (Printf.sprintf
"failed to execute %s: %s"
931 conf.selcmd
(exntos exn
));
935 Ne.clo fd
(fun msg
->
936 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
942 let l = String.length s
in
943 let n = tempfailureretry
(Unix.write w s
0) l in
948 "failed to write %d characters to sel pipe, wrote %d"
953 (Printf.sprintf
"failed to write to sel pipe: %s"
962 let undertext = function
965 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
966 | Utext s
-> "font: " ^ s
967 | Uunexpected s
-> "unexpected: " ^ s
968 | Ulaunch s
-> "launch: " ^ s
969 | Unamed s
-> "named: " ^ s
970 | Uremote
(filename
, pageno
) ->
971 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
974 let updateunder x y =
975 match getunder x y with
976 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
978 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
979 Wsi.setcursor
Wsi.CURSOR_INFO
980 | Ulinkgoto
(pageno
, _
) ->
982 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
983 Wsi.setcursor
Wsi.CURSOR_INFO
985 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
986 Wsi.setcursor
Wsi.CURSOR_TEXT
988 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
989 Wsi.setcursor
Wsi.CURSOR_INHERIT
991 if conf.underinfo
then showtext '
l'
("aunch: " ^ s
);
992 Wsi.setcursor
Wsi.CURSOR_INHERIT
994 if conf.underinfo
then showtext '
n'
("amed: " ^ s
);
995 Wsi.setcursor
Wsi.CURSOR_INHERIT
996 | Uremote
(filename
, pageno
) ->
997 if conf.underinfo
then showtext 'r'
998 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
999 Wsi.setcursor
Wsi.CURSOR_INFO
1002 let showlinktype under
=
1008 let s = undertext under
in
1013 let b = Buffer.create
(String.length
s + 1) in
1014 Buffer.add_string
b s;
1015 Buffer.add_char
b c
;
1019 let colorspace_of_string s =
1020 match String.lowercase
s with
1024 | _
-> failwith
"invalid colorspace"
1027 let int_of_colorspace = function
1033 let colorspace_of_int = function
1037 | n -> failwith
("invalid colorspace index " ^ string_of_int
n)
1040 let colorspace_to_string = function
1046 let fitmodel_of_string s =
1047 match String.lowercase
s with
1048 | "width" -> FitWidth
1049 | "proportional" -> FitProportional
1051 | _
-> failwith
"invalid fit model"
1054 let int_of_fitmodel = function
1056 | FitProportional
-> 1
1060 let fitmodel_of_int = function
1062 | 1 -> FitProportional
1064 | n -> failwith
("invalid fit model index " ^ string_of_int
n)
1067 let fitmodel_to_string = function
1068 | FitWidth
-> "width"
1069 | FitProportional
-> "proportional"
1073 let intentry_with_suffix text key
=
1075 if key
>= 32 && key
< 127
1079 match Char.lowercase
c with
1081 let text = addchar text c in
1084 | 'k'
| 'm'
| '
g'
->
1085 let text = addchar text c in
1089 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1093 let multicolumns_to_string (n, a
, b) =
1095 then Printf.sprintf
"%d" n
1096 else Printf.sprintf
"%d,%d,%d" n a
b;
1099 let multicolumns_of_string s =
1101 (int_of_string
s, 0, 0)
1103 Scanf.sscanf
s "%u,%u,%u" (fun n a
b ->
1105 then failwith
"subtly broken"; (n, a
, b)
1111 let n = tempfailureretry
(Unix.read fd
s 0) 4 in
1112 if n != 4 then failwith
"incomplete read(len)";
1114 lor (Char.code
s.[0] lsl 24)
1115 lor (Char.code
s.[1] lsl 16)
1116 lor (Char.code
s.[2] lsl 8)
1117 lor (Char.code
s.[3] lsl 0)
1119 let s = String.create
len in
1120 let n = tempfailureretry
(Unix.read fd
s 0) len in
1121 if n != len then failwith
"incomplete read(data)";
1125 let btod b = if b then 1 else 0;;
1128 let b = Buffer.create
16 in
1129 Buffer.add_string
b "llll";
1132 let s = Buffer.contents
b in
1133 let n = String.length
s in
1135 (* dolog "wcmd %S" (String.sub s 4 len); *)
1136 s.[0] <- Char.chr
((len lsr 24) land 0xff);
1137 s.[1] <- Char.chr
((len lsr 16) land 0xff);
1138 s.[2] <- Char.chr
((len lsr 8) land 0xff);
1139 s.[3] <- Char.chr
(len land 0xff);
1140 let n'
= tempfailureretry
(Unix.write
state.sw
s 0) n in
1141 if n'
!= n then failwith
"write failed";
1146 let d = state.winh
- h
in
1147 max
conf.interpagespace
((d + 1) / 2)
1150 let rowyh (c, coverA
, coverB
) b n =
1151 if c = 1 || (n < coverA
|| n >= state.pagecount
- coverB
)
1153 let _, _, vy
, (_, _, h
, _) = b.(n) in
1156 let n'
= n - coverA
in
1159 let e = min
state.pagecount
(s + c) in
1160 let rec find m miny maxh
= if m
= e then miny
, maxh
else
1161 let _, _, y, (_, _, h
, _) = b.(m
) in
1162 let miny = min
miny y in
1163 let maxh = max
maxh h
in
1164 find (m
+1) miny maxh
1169 match conf.columns
with
1170 | Cmulti
((_, _, _) as cl
, b) ->
1171 if Array.length
b > 0
1173 let y, h
= rowyh cl
b (Array.length
b - 1) in
1174 y + h
+ (if conf.presentation
then calcips h
else 0)
1177 if Array.length
b > 0
1179 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1180 y + h
+ (if conf.presentation
then calcips h
else 0)
1183 if Array.length
b > 0
1185 let (_, _, y, (_, _, h
, _)) = b.(Array.length
b - 1) in
1190 let getpageyh pageno
=
1191 let pageno = bound pageno 0 (state.pagecount
-1) in
1192 match conf.columns
with
1194 if Array.length
b = 0
1197 let (_, _, y, (_, _, h
, _)) = b.(pageno) in
1199 if conf.presentation
1205 if Array.length
b = 0
1208 let y, h
= rowyh cl
b pageno in
1210 if conf.presentation
1216 if Array.length
b = 0
1220 let (_, _, y, (_, _, h
, _)) = b.(n) in
1224 let getpagedim pageno =
1227 | (n, _, _, _) as pdim
:: rest
->
1229 then (if n = pageno then pdim
else ppdim
)
1234 f (-1, -1, -1, -1) state.pdims
1237 let getpagey pageno = fst
(getpageyh pageno);;
1239 let nogeomcmds cmds
=
1241 | s, [] -> String.length
s = 0
1246 let ((c, coverA
, coverB
) as cl
), b =
1247 match conf.columns
with
1248 | Csingle
b -> (1, 0, 0), b
1249 | Cmulti
(c, b) -> c, b
1250 | Csplit
(_, b) -> (1, 0, 0), b
1252 if Array.length
b = 0
1255 let rec bsearch nmin nmax
=
1257 then bound nmin
0 (state.pagecount
-1)
1259 let n = (nmax
+ nmin
) / 2 in
1260 let vy, h
= rowyh cl
b n in
1262 if conf.presentation
1264 let ips = calcips h
in
1265 let y0 = vy - ips in
1266 let y1 = vy + h
+ ips in
1270 then 0, vy + h
+ conf.interpagespace
1272 let y0 = vy - conf.interpagespace
in
1273 y0, y0 + h
+ conf.interpagespace
1276 if y >= y0 && y < y1
1283 if n < state.pagecount
- coverB
1284 then ((n-coverA
)/c)*c + coverA
1291 then bsearch (n+1) nmax
1292 else bsearch nmin
(n-1)
1295 let r = bsearch 0 (state.pagecount
-1) in
1299 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1300 let sh = sh - (hscrollh ()) in
1301 let rec fold accu
n =
1302 if n = Array.length
b
1305 let pdimno, dx, vy, (_, w
, h
, xoff
) = b.(n) in
1308 || n = state.pagecount
- coverB
1309 || (n - coverA
) mod columns
= columns
- 1)
1315 let pagey = max
0 (y - vy) in
1316 let pagedispy = if pagey > 0 then 0 else vy - y in
1317 let pagedispx, pagex
=
1319 if n = coverA
- 1 || n = state.pagecount
- coverB
1320 then state.x + (wadjsb state.winw
- w
) / 2
1321 else dx + xoff
+ state.x
1328 let vw = wadjsb state.winw
- pagedispx in
1329 let pw = w
- pagex
in
1332 let pagevh = min
(h
- pagey) (sh - pagedispy) in
1333 if pagevw > 0 && pagevh > 0
1337 ; pagedimno
= pdimno
1344 ; pagedispx = pagedispx
1345 ; pagedispy = pagedispy
1357 List.rev
(fold [] (page_of_y y));
1360 let layoutS (columns
, b) y sh =
1361 let sh = sh - hscrollh () in
1362 let rec fold accu n =
1363 if n = Array.length
b
1366 let pdimno, px, vy, (_, pagew
, pageh
, xoff
) = b.(n) in
1373 let x = xoff
+ state.x in
1374 let pagey = max
0 (y - vy) in
1375 let pagedispy = if pagey > 0 then 0 else vy - y in
1376 let pagedispx, pagex
=
1390 let pagecolw = pagew
/columns
in
1392 if pagecolw < state.winw
1393 then pagedispx + ((wadjsb state.winw
- pagecolw) / 2)
1397 let vw = wadjsb state.winw
- pagedispx in
1398 let pw = pagew
- pagex
in
1401 let pagevw = min
pagevw pagecolw in
1402 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1403 if pagevw > 0 && pagevh > 0
1406 { pageno = n/columns
1407 ; pagedimno
= pdimno
1414 ; pagedispx = pagedispx
1415 ; pagedispy = pagedispy
1416 ; pagecol
= n mod columns
1427 List.rev
(fold [] 0)
1431 if nogeomcmds state.geomcmds
1433 match conf.columns
with
1434 | Csingle
b -> layoutN ((1, 0, 0), b) y sh
1435 | Cmulti
c -> layoutN c y sh
1436 | Csplit
s -> layoutS s y sh
1441 let y = state.y + incr
in
1443 let y = min
y (state.maxy
- (if conf.maxhfit
then state.winh
else 0)) in
1448 let tilex = l.pagex
mod conf.tilew
in
1449 let tiley = l.pagey mod conf.tileh
in
1451 let col = l.pagex
/ conf.tilew
in
1452 let row = l.pagey / conf.tileh
in
1454 let rec rowloop row y0 dispy h
=
1458 let dh = conf.tileh
- y0 in
1459 let dh = min h
dh in
1460 let rec colloop col x0 dispx w
=
1464 let dw = conf.tilew
- x0 in
1465 let dw = min w
dw in
1467 f col row dispx dispy
x0 y0 dw dh;
1468 colloop (col+1) 0 (dispx
+dw) (w
-dw)
1471 colloop col tilex l.pagedispx l.pagevw;
1472 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
1475 if l.pagevw > 0 && l.pagevh > 0
1476 then rowloop row tiley l.pagedispy l.pagevh;
1479 let gettileopaque l col row =
1481 l.pageno, state.gen
, conf.colorspace
, conf.angle
, l.pagew
, l.pageh
, col, row
1483 try Some
(Hashtbl.find state.tilemap
key)
1484 with Not_found
-> None
1487 let puttileopaque l col row gen colorspace angle opaque size elapsed
=
1488 let key = l.pageno, gen
, colorspace
, angle
, l.pagew
, l.pageh
, col, row in
1489 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1492 let drawtiles l color
=
1494 let f col row x y tilex tiley w h
=
1495 match gettileopaque l col row with
1496 | Some
(opaque
, _, t
) ->
1497 let params = x, y, w
, h
, tilex, tiley in
1501 GlFunc.blend_func `zero `one_minus_src_color
;
1503 drawtile
params opaque
;
1505 then Gl.disable `blend
;
1508 let s = Printf.sprintf
1512 let w = measurestr
fstate.fontsize
s in
1513 GlMisc.push_attrib
[`current
];
1514 GlDraw.color
(0.0, 0.0, 0.0);
1516 (float (x-2), float (y-2))
1517 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1518 GlDraw.color
(1.0, 1.0, 1.0);
1519 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1520 GlMisc.pop_attrib
();
1525 let lw = wadjsb state.winw
- x in
1528 let lh = state.winh
- y in
1531 begin match state.texid
with
1533 Gl.enable `texture_2d
;
1534 GlTex.bind_texture `texture_2d id
;
1537 and x1 = float (x+w)
1538 and y1 = float (y+h
) in
1540 let tw = float w /. 16.0
1541 and th
= float h
/. 16.0 in
1542 let tx0 = float tilex /. 16.0
1543 and ty0
= float tiley /. 16.0 in
1545 and ty1
= ty0
+. th
in
1546 GlDraw.begins `quads
;
1547 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1548 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1549 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1550 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1553 Gl.disable `texture_2d
;
1555 GlDraw.color
(1.0, 1.0, 1.0);
1558 (float (x+w), float (y+h
));
1560 if w > 128 && h
> fstate.fontsize
+ 10
1562 GlDraw.color
(0.0, 0.0, 0.0);
1565 then (col*conf.tilew
, row*conf.tileh
)
1568 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l.pageno c r;
1575 let pagevisible layout n = List.exists
(fun l -> l.pageno = n) layout;;
1577 let tilevisible1 l x y =
1579 and ax1
= l.pagex
+ l.pagevw
1581 and ay1
= l.pagey + l.pagevh in
1585 let bx1 = min
(bx0 + conf.tilew
) l.pagew
1586 and by1
= min
(by0
+ conf.tileh
) l.pageh
in
1588 let rx0 = max
ax0 bx0
1589 and ry0
= max ay0 by0
1590 and rx1
= min ax1
bx1
1591 and ry1
= min ay1 by1
in
1593 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1594 nonemptyintersection
1597 let tilevisible layout n x y =
1598 let rec findpageinlayout m
= function
1599 | l :: rest
when l.pageno = n ->
1600 tilevisible1 l x y || (
1601 match conf.columns
with
1602 | Csplit
(c, _) when c > m
-> findpageinlayout (m
+1) rest
1605 | _ :: rest
-> findpageinlayout 0 rest
1608 findpageinlayout 0 layout;
1611 let tileready l x y =
1612 tilevisible1 l x y &&
1613 gettileopaque l (x/conf.tilew
) (y/conf.tileh
) != None
1616 let tilepage n p
layout =
1617 let rec loop = function
1621 let f col row _ _ _ _ _ _ =
1622 if state.currently
= Idle
1624 match gettileopaque l col row with
1627 let x = col*conf.tilew
1628 and y = row*conf.tileh
in
1630 let w = l.pagew
- x in
1634 let h = l.pageh
- y in
1639 then getpbo
w h conf.colorspace
1642 wcmd "tile %s %d %d %d %d %s" p
x y w h pbo;
1645 l, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1646 conf.tilew
, conf.tileh
1655 if nogeomcmds state.geomcmds
1659 let preloadlayout y =
1660 let y = if y < state.winh
then 0 else y - state.winh
in
1661 let h = state.winh
*3 in
1666 let rec loop pages
=
1667 if state.currently
!= Idle
1672 begin match getopaque l.pageno with
1674 wcmd "page %d %d" l.pageno l.pagedimno
;
1675 state.currently
<- Loading
(l, state.gen
);
1677 tilepage l.pageno opaque pages
;
1682 if nogeomcmds state.geomcmds
1688 if conf.preload && state.currently
= Idle
1689 then load (preloadlayout state.y);
1692 let layoutready layout =
1693 let rec fold all ls
=
1694 all
&& match ls
with
1696 let seen = ref false in
1697 let allvisible = ref true in
1698 let foo col row _ _ _ _ _ _ =
1700 allvisible := !allvisible &&
1701 begin match gettileopaque l col row with
1707 fold (!seen && !allvisible) rest
1710 let alltilesvisible = fold true layout in
1715 let y = bound y 0 state.maxy
in
1716 let y, layout, proceed
=
1717 match conf.maxwait
with
1718 | Some time
when state.ghyll
== noghyll ->
1719 begin match state.throttle
with
1721 let layout = layout y state.winh
in
1722 let ready = layoutready layout in
1726 state.throttle
<- Some
(layout, y, now ());
1728 else G.postRedisplay "gotoy showall (None)";
1730 | Some
(_, _, started
) ->
1731 let dt = now () -. started
in
1734 state.throttle
<- None
;
1735 let layout = layout y state.winh
in
1737 G.postRedisplay "maxwait";
1744 let layout = layout y state.winh
in
1745 if not
!wtmode || layoutready layout
1746 then G.postRedisplay "gotoy ready";
1752 state.layout <- layout;
1753 begin match state.mode
with
1754 | LinkNav
(Ltexact
(pageno, linkno
)) ->
1755 let rec loop = function
1757 state.mode
<- LinkNav
(Ltgendir
0)
1758 | l :: _ when l.pageno = pageno ->
1759 begin match getopaque pageno with
1761 state.mode
<- LinkNav
(Ltgendir
0)
1763 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1764 if not
(x0 >= l.pagex
&& x1 <= l.pagex
+ l.pagevw
1765 && y0 >= l.pagey && y1 <= l.pagey + l.pagevh)
1766 then state.mode
<- LinkNav
(Ltgendir
0)
1768 | _ :: rest
-> loop rest
1773 begin match state.mode
with
1774 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor
) ->
1775 if not
(pagevisible layout pageno)
1777 match state.layout with
1780 state.mode
<- Birdseye
(
1781 conf, leftx
, l.pageno, hooverpageno
, anchor
1784 | LinkNav
(Ltgendir dir
as lt
) ->
1786 let rec loop = function
1789 match getopaque l.pageno with
1795 then LDfirstvisible
(l.pagex
, l.pagey, dir
)
1797 if dir
> 0 then LDfirst
else LDlast
1803 | Lnotfound
-> loop rest
1805 showlinktype (getlink opaque
n);
1806 Ltexact
(l.pageno, n)
1810 state.mode
<- LinkNav
linknav
1815 state.ghyll
<- noghyll;
1818 let mx, my
= state.mpos
in
1823 let conttiling pageno opaque
=
1824 tilepage pageno opaque
1825 (if conf.preload then preloadlayout state.y else state.layout)
1828 let gotoy_and_clear_text y =
1829 if not
conf.verbose
then state.text <- "";
1835 let coloff = l.pagecol
* l.pageh
in
1836 float (l.pagey + coloff) /. float l.pageh
1843 if conf.presentation
1844 then float l.pagedispy /. float (calcips l.pageh
)
1845 else float l.pagedispy /. float conf.interpagespace
1848 (l.pageno, top, dtop)
1852 match state.layout with
1853 | l :: _ -> getanchor1 l
1855 let n = page_of_y state.y in
1859 let y, h = getpageyh n in
1860 let dy = y - state.y in
1862 if conf.presentation
1864 let ips = calcips h in
1865 float (dy + ips) /. float ips
1867 float dy /. float conf.interpagespace
1872 let getanchory (n, top, dtop) =
1873 let y, h = getpageyh n in
1874 if conf.presentation
1876 let ips = calcips h in
1877 y + truncate
(top*.float h -. dtop*.float ips) + ips;
1879 y + truncate
(top*.float h -. dtop*.float conf.interpagespace
)
1882 let gotoanchor anchor
=
1883 gotoy (getanchory anchor
);
1887 cbput state.hists
.nav
(getanchor ());
1891 let anchor = cbgetc state.hists
.nav dir
in
1896 let scroll f n a
b =
1897 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1899 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1901 then s (float f /. float a
)
1904 then 1.0 -. s ((float (f-b) /. float (n-b)))
1910 (* courtesy: (calc-eval "integ(3x^2-2x^3,x)") *)
1911 let iv x = x**3.-.0.5*.x**4. in
1913 let ins = float a
*. iv1
1914 and outs
= float (n-b) *. iv1 in
1916 ins +. outs
+. float ones
1918 let rec set (_N
, _A
, _B
) y sy
=
1919 let sum = summa
1.0 _N _A _B
in
1920 let dy = float (y - sy
) in
1924 then state.ghyll
<- noghyll
1927 let s = scroll n _N _A _B
in
1928 let y1 = y1 +. ((s *. dy) /. sum) in
1929 gotoy_and_clear_text (truncate
y1);
1930 state.ghyll
<- gf (n+1) y1;
1934 | Some
y'
-> set (_N
/2, 1, 1) y'
state.y
1936 gf 0 (float state.y)
1939 match conf.ghyllscroll
with
1941 gotoy_and_clear_text y
1943 if state.ghyll
== noghyll
1944 then set nab
y state.y
1945 else state.ghyll
(Some
y)
1948 let gotopage n top =
1949 let y, h = getpageyh n in
1950 let y = y + (truncate
(top *. float h)) in
1954 let gotopage1 n top =
1955 let y = getpagey n in
1960 let invalidate s f =
1965 match state.geomcmds
with
1966 | ps
, [] when String.length ps
= 0 ->
1968 state.geomcmds
<- s, [];
1971 state.geomcmds
<- ps
, [s, f];
1973 | ps
, (s'
, _) :: rest
when s'
= s ->
1974 state.geomcmds
<- ps
, ((s, f) :: rest
);
1977 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1981 Hashtbl.iter
(fun _ opaque
->
1982 wcmd "freepage %s" opaque
;
1984 Hashtbl.clear
state.pagemap
;
1988 if not
(Queue.is_empty
state.tilelru
)
1990 Queue.iter
(fun (k
, p
, s) ->
1991 wcmd "freetile %s" p
;
1992 state.memused
<- state.memused
- s;
1993 Hashtbl.remove
state.tilemap k
;
1995 state.uioh#infochanged Memused
;
1996 Queue.clear
state.tilelru
;
2002 let h = truncate
(float h*.conf.zoom
) in
2003 let d = conf.interpagespace
lsl (if conf.presentation
then 1 else 0) in
2007 let opendoc path password
=
2009 state.password
<- password
;
2010 state.gen
<- state.gen
+ 1;
2011 state.docinfo
<- [];
2014 setaalevel
conf.aalevel
;
2016 if String.length
state.origin
= 0
2020 Wsi.settitle
("llpp " ^
(mbtoutf8
(Filename.basename
titlepath)));
2021 wcmd "open %d %s\000%s\000" (btod !wtmode) path password
;
2022 invalidate "reqlayout"
2024 wcmd "reqlayout %d %d %d %s\000"
2025 conf.angle
(int_of_fitmodel conf.fitmodel
)
2026 (stateh state.winh
) state.nameddest
2031 state.anchor <- getanchor ();
2032 opendoc state.path
state.password
;
2036 let c = c *. conf.colorscale
in
2040 let scalecolor2 (r, g, b) =
2041 (r *. conf.colorscale
, g *. conf.colorscale
, b *. conf.colorscale
);
2044 let docolumns = function
2046 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2047 let rec loop pageno pdimno pdim
y ph pdims
=
2048 if pageno = state.pagecount
2051 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2053 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2054 pdimno+1, pdim
, rest
2058 let x = max
0 (((wadjsb state.winw
- w) / 2) - xoff
) in
2060 (if conf.presentation
2061 then (if pageno = 0 then calcips h else calcips ph
+ calcips h)
2062 else (if pageno = 0 then 0 else conf.interpagespace
)
2065 a.(pageno) <- (pdimno, x, y, pdim
);
2066 loop (pageno+1) pdimno pdim
(y + h) h pdims
2068 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state.pdims
;
2069 conf.columns
<- Csingle
a;
2071 | Cmulti
((columns
, coverA
, coverB
), _) ->
2072 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
2073 let rec loop pageno pdimno pdim
x y rowh pdims
=
2074 let rec fixrow m
= if m
= pageno then () else
2075 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
2078 let y = y + (rowh
- h) / 2 in
2079 a.(m
) <- (pdimno, x, y, pdim
);
2083 if pageno = state.pagecount
2084 then fixrow (((pageno - 1) / columns
) * columns
)
2086 let pdimno, ((_, w, h, xoff
) as pdim
), pdims
=
2088 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2089 pdimno+1, pdim
, rest
2094 if pageno = coverA
- 1 || pageno = state.pagecount
- coverB
2096 let x = (wadjsb state.winw
- w) / 2 in
2098 if conf.presentation
then calcips h else conf.interpagespace
in
2099 x, y + ips + rowh
, h
2102 if (pageno - coverA
) mod columns
= 0
2104 let x = max
0 (wadjsb state.winw
- state.w) / 2 in
2106 if conf.presentation
2108 let ips = calcips h in
2109 y + (if pageno = 0 then 0 else calcips rowh
+ ips)
2111 y + (if pageno = 0 then 0 else conf.interpagespace
)
2115 else x, y, max rowh
h
2119 if pageno > 1 && (pageno - coverA
) mod columns
= 0
2122 if pageno = columns
&& conf.presentation
2124 let ips = calcips rowh
in
2125 for i
= 0 to pred columns
2127 let (pdimno, x, y, pdim
) = a.(i
) in
2128 a.(i
) <- (pdimno, x, y+ips, pdim
)
2134 fixrow (pageno - columns
);
2139 a.(pageno) <- (pdimno, x, y, pdim
);
2140 let x = x + w + xoff
*2 + conf.interpagespace
in
2141 loop (pageno+1) pdimno pdim
x y rowh' pdims
2143 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
2144 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
2147 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
2148 let rec loop pageno pdimno pdim
y pdims
=
2149 if pageno = state.pagecount
2152 let pdimno, ((_, w, h, _) as pdim
), pdims
=
2154 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno ->
2155 pdimno+1, pdim
, rest
2160 let rec loop1 n x y =
2161 if n = c then y else (
2162 a.(pageno*c + n) <- (pdimno, x, y, pdim
);
2163 loop1 (n+1) (x+cw) (y + h + conf.interpagespace
)
2166 let y = loop1 0 0 y in
2167 loop (pageno+1) pdimno pdim
y pdims
2169 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
2170 conf.columns
<- Csplit
(c, a);
2174 docolumns conf.columns
;
2175 state.maxy
<- calcheight ();
2176 if state.reprf
== noreprf
2178 match state.mode
with
2179 | Birdseye
(_, _, pageno, _, _) ->
2180 let y, h = getpageyh pageno in
2181 let top = (state.winh
- h) / 2 in
2182 gotoy (max
0 (y - top))
2183 | _ -> gotoanchor state.anchor
2187 state.reprf
<- noreprf;
2192 GlDraw.viewport
0 0 w h;
2193 let firsttime = state.geomcmds
== firstgeomcmds in
2194 if not
firsttime && nogeomcmds state.geomcmds
2195 then state.anchor <- getanchor ();
2198 let w = wadjsb (truncate
(float w *. conf.zoom
)) in
2201 setfontsize fstate.fontsize
;
2202 GlMat.mode `modelview
;
2203 GlMat.load_identity
();
2205 GlMat.mode `projection
;
2206 GlMat.load_identity
();
2207 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2208 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2209 GlMat.scale3
(2.0 /. float state.winw
, 2.0 /. float state.winh
, 1.0);
2214 else float state.x /. float state.w
2216 invalidate "geometry"
2220 then state.x <- truncate
(relx *. float w);
2222 match conf.columns
with
2224 | Cmulti
((c, _, _), _) -> (w - (c-1)*conf.interpagespace
) / c
2225 | Csplit
(c, _) -> w * c
2227 wcmd "geometry %d %d %d"
2228 w (stateh h) (int_of_fitmodel conf.fitmodel
)
2233 let len = String.length
state.text in
2236 match state.mode
with
2237 | Textentry
_ | View
| LinkNav
_ ->
2238 let h, _, _ = state.uioh#scrollpw
in
2244 (x, float (state.winh
- (fstate.fontsize
+ 4) - hscrollh))
2245 (x+.w, float (state.winh
- hscrollh))
2248 let w = float (wadjsb state.winw
- 1) in
2249 if state.progress
>= 0.0 && state.progress
< 1.0
2251 GlDraw.color
(0.3, 0.3, 0.3);
2252 let w1 = w *. state.progress
in
2254 GlDraw.color
(0.0, 0.0, 0.0);
2258 GlDraw.color
(0.0, 0.0, 0.0);
2262 GlDraw.color
(1.0, 1.0, 1.0);
2263 drawstring fstate.fontsize
2264 (if len > 0 then 8 else 2) (state.winh
- hscrollh - 5) s;
2267 match state.mode
with
2268 | Textentry
((prefix
, text, _, _, _, _), _) ->
2272 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2274 Printf.sprintf
"%s%s_" prefix
text
2283 if not
(istextentry state.mode
) && state.uioh#eformsgs
2285 let s1 = "(press 'e' to review error messasges)" in
2286 if String.length
s > 0 then s ^
" " ^
s1 else s1
2291 if String.length
s > 0
2296 let len = Queue.length
state.tilelru
in
2298 match state.throttle
with
2301 then preloadlayout state.y
2303 | Some
(layout, _, _) ->
2307 if state.memused
<= conf.memlimit
2312 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2313 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2314 let (_, pw, ph
, _) = getpagedim n in
2317 && colorspace
= conf.colorspace
2318 && angle
= conf.angle
2322 let x = col*conf.tilew
2323 and y = row*conf.tileh
in
2324 tilevisible (Lazy.force_val
layout) n x y
2326 then Queue.push lruitem
state.tilelru
2329 wcmd "freetile %s" p
;
2330 state.memused
<- state.memused
- s;
2331 state.uioh#infochanged Memused
;
2332 Hashtbl.remove
state.tilemap k
;
2340 let logcurrently = function
2341 | Idle
-> dolog
"Idle"
2342 | Loading
(l, gen
) ->
2343 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2344 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2346 "Tiling %d[%d,%d] page=%s cs=%s angle"
2347 l.pageno col row pageopaque
2348 (colorspace_to_string colorspace
)
2350 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2351 angle gen
conf.angle
state.gen
2353 conf.tilew
conf.tileh
2360 let r = Str.regexp
" " in
2361 fun s -> Str.bounded_split
r s 2;
2364 let onpagerect pageno f =
2366 match conf.columns
with
2367 | Cmulti
(_, b) -> b
2369 | Csplit
(_, b) -> b
2371 if pageno >= 0 && pageno < Array.length
b
2373 let (pdimno, _, _, (_, _, _, _)) = b.(pageno) in
2374 let r = getpdimrect
pdimno in
2375 f (r.(1)-.r.(0)) (r.(3)-.r.(2))
2378 let gotopagexy1 pageno x y =
2379 onpagerect pageno (fun w h ->
2381 let _,w1,_,leftx
= getpagedim pageno in
2382 let wh = state.winh
- hscrollh () in
2383 let sw = float w1 /. w in
2385 let x = leftx
+ state.x + truncate
x in
2387 if x < 0 || x >= wadjsb state.winw
2391 let py, h = getpageyh pageno in
2392 let pdy = truncate
(top *. float h) in
2393 let y'
= py + pdy in
2394 let dy = y'
- state.y in
2396 if x != state.x || not
(dy > 0 && dy < wh)
2398 if conf.presentation
2400 if abs
(py - y'
) > wh
2407 if state.x != sx || state.y != sy
2412 let ww = wadjsb state.winw
in
2414 and qy
= pdy / wh in
2416 and y = py + qy
* wh in
2417 let x = if -x + ww > w1 then -(w1-ww) else x
2418 and y'
= if y + wh > state.maxy
then state.maxy
- wh else y in
2420 if conf.presentation
2422 if abs
(py - y'
) > wh
2432 gotoy_and_clear_text y;
2434 else gotoy_and_clear_text state.y;
2438 let gotopagexy pageno x y =
2439 match state.mode
with
2440 | Birdseye
_ -> gotopage pageno 0.0
2441 | _ -> gotopagexy1 pageno x y
2445 (* dolog "%S" cmds; *)
2446 let cl = splitatspace cmds
in
2448 try Scanf.sscanf
s fmt
f
2450 dolog
"error processing '%S': %s" cmds
(exntos exn
);
2455 state.uioh#infochanged Pdim
;
2458 | "clearrects" :: [] ->
2459 state.rects
<- state.rects1
;
2460 G.postRedisplay "clearrects";
2462 | "continue" :: args :: [] ->
2463 let n = scan args "%u" (fun n -> n) in
2464 state.pagecount
<- n;
2465 begin match state.currently
with
2467 state.currently
<- Idle
;
2468 state.outlines
<- Array.of_list
(List.rev
l)
2472 let cur, cmds
= state.geomcmds
in
2473 if String.length
cur = 0
2474 then failwith
"umpossible";
2476 begin match List.rev cmds
with
2478 state.geomcmds
<- "", [];
2482 state.geomcmds
<- s, List.rev rest
;
2484 if conf.maxwait
= None
&& not
!wtmode
2485 then G.postRedisplay "continue";
2487 | "title" :: args :: [] ->
2490 | "msg" :: args :: [] ->
2493 | "vmsg" :: args :: [] ->
2495 then showtext ' '
args
2497 | "emsg" :: args :: [] ->
2498 Buffer.add_string
state.errmsgs
args;
2499 state.newerrmsgs
<- true;
2500 G.postRedisplay "error message"
2502 | "progress" :: args :: [] ->
2503 let progress, text =
2506 f, String.sub
args pos
(String.length
args - pos
))
2509 state.progress <- progress;
2510 G.postRedisplay "progress"
2512 | "firstmatch" :: args :: [] ->
2513 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2514 scan args "%u %d %f %f %f %f %f %f %f %f"
2515 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2516 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2518 let y = (getpagey pageno) + truncate
y0 in
2521 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2523 | "match" :: args :: [] ->
2524 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2525 scan args "%u %d %f %f %f %f %f %f %f %f"
2526 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2527 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2530 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2532 | "page" :: args :: [] ->
2533 let pageopaque, t
= scan args "%s %f" (fun p t
-> p
, t
) in
2534 begin match state.currently
with
2535 | Loading
(l, gen
) ->
2536 vlog "page %d took %f sec" l.pageno t
;
2537 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2538 begin match state.throttle
with
2540 let preloadedpages =
2542 then preloadlayout state.y
2547 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2548 IntSet.empty
preloadedpages
2551 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
2552 if not
(IntSet.mem
pageno set)
2554 wcmd "freepage %s" opaque
;
2560 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2563 state.currently
<- Idle
;
2566 tilepage l.pageno pageopaque state.layout;
2568 load preloadedpages;
2569 if pagevisible state.layout l.pageno
2570 && layoutready state.layout
2571 then G.postRedisplay "page";
2574 | Some
(layout, _, _) ->
2575 state.currently
<- Idle
;
2576 tilepage l.pageno pageopaque layout;
2581 dolog
"Inconsistent loading state";
2582 logcurrently state.currently
;
2586 | "tile" :: args :: [] ->
2587 let (x, y, opaque
, size
, t
) =
2588 scan args "%u %u %s %u %f"
2589 (fun x y p size t
-> (x, y, p
, size
, t
))
2591 begin match state.currently
with
2592 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2593 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2596 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2598 wcmd "freetile %s" opaque
;
2599 state.currently
<- Idle
;
2603 puttileopaque l col row gen cs angle opaque size t
;
2604 state.memused
<- state.memused
+ size
;
2605 state.uioh#infochanged Memused
;
2607 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2608 opaque
, size
) state.tilelru
;
2611 match state.throttle
with
2612 | None
-> state.layout
2613 | Some
(layout, _, _) -> layout
2616 state.currently
<- Idle
;
2618 && conf.colorspace
= cs
2619 && conf.angle
= angle
2620 && tilevisible layout l.pageno x y
2621 then conttiling l.pageno pageopaque;
2623 begin match state.throttle
with
2625 preload state.layout;
2627 && conf.colorspace
= cs
2628 && conf.angle
= angle
2629 && tilevisible state.layout l.pageno x y
2630 && (not
!wtmode || layoutready state.layout)
2631 then G.postRedisplay "tile nothrottle";
2633 | Some
(layout, y, _) ->
2634 let ready = layoutready layout in
2638 state.layout <- layout;
2639 state.throttle
<- None
;
2640 G.postRedisplay "throttle";
2647 dolog
"Inconsistent tiling state";
2648 logcurrently state.currently
;
2652 | "pdim" :: args :: [] ->
2653 let (n, w, h, _) as pdim
=
2654 scan args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2657 match conf.fitmodel
, conf.columns
with
2658 | (FitPage
| FitProportional
), Csplit
_ -> (n, w, h, 0)
2661 state.uioh#infochanged Pdim
;
2662 state.pdims
<- pdim :: state.pdims
2664 | "o" :: args :: [] ->
2665 let (l, n, t
, h, pos
) =
2666 scan args "%u %u %d %u %n"
2667 (fun l n t
h pos
-> l, n, t
, h, pos
)
2669 let s = String.sub
args pos
(String.length
args - pos
) in
2670 let outline = (s, l, (n, float t
/. float h, 0.0)) in
2671 begin match state.currently
with
2672 | Outlining outlines
->
2673 state.currently
<- Outlining
(outline :: outlines
)
2675 state.currently
<- Outlining
[outline]
2677 dolog
"invalid outlining state";
2678 logcurrently currently
2681 | "a" :: args :: [] ->
2683 scan args "%u %d %d" (fun n l t
-> n, l, t
)
2685 state.reprf
<- (fun () -> gotopagexy n (float l) (float t
))
2687 | "info" :: args :: [] ->
2688 state.docinfo
<- (1, args) :: state.docinfo
2690 | "infoend" :: [] ->
2691 state.uioh#infochanged Docinfo
;
2692 state.docinfo
<- List.rev
state.docinfo
2695 failwith
(Printf.sprintf
"unknown cmd `%S'" cmds
)
2700 let action = function
2701 | HCprev
-> cbget cb ~
-1
2702 | HCnext
-> cbget cb
1
2703 | HCfirst
-> cbget cb ~
-(cb
.rc)
2704 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2705 and cancel
() = cb
.rc <- rc
2709 let search pattern forward
=
2710 match conf.columns
with
2712 showtext '
!'
"searching does not work properly in split columns mode"
2714 if String.length pattern
> 0
2717 match state.layout with
2720 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2722 wcmd "search %d %d %d %d,%s\000"
2723 (btod conf.icase
) pn py (btod forward
) pattern
;
2726 let intentry text key =
2728 if key >= 32 && key < 127
2734 let text = addchar text c in
2738 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2742 let linknentry text key =
2744 if key >= 32 && key < 127
2750 let text = addchar text c in
2754 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2759 if String.length
s > 0
2762 let l = String.length
s in
2763 let rec loop pos
n = if pos
= l then n else
2764 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2765 loop (pos
+1) (n*26 + m)
2768 let rec loop n = function
2771 match getopaque l.pageno with
2772 | None
-> loop n rest
2774 let m = getlinkcount opaque
in
2777 let under = getlink opaque
n in
2780 else loop (n-m) rest
2782 loop n state.layout;
2786 let textentry text key =
2787 if key land 0xff00 = 0xff00
2789 else TEcont
(text ^ toutf8
key)
2792 let reqlayout angle fitmodel
=
2793 match state.throttle
with
2795 if nogeomcmds state.geomcmds
2796 then state.anchor <- getanchor ();
2797 conf.angle
<- angle
mod 360;
2800 match state.mode
with
2801 | LinkNav
_ -> state.mode
<- View
2804 conf.fitmodel
<- fitmodel
;
2805 invalidate "reqlayout"
2807 wcmd "reqlayout %d %d %d"
2808 conf.angle
(int_of_fitmodel conf.fitmodel
) (stateh state.winh
)
2813 let settrim trimmargins trimfuzz
=
2814 if nogeomcmds state.geomcmds
2815 then state.anchor <- getanchor ();
2816 conf.trimmargins
<- trimmargins
;
2817 conf.trimfuzz
<- trimfuzz
;
2818 let x0, y0, x1, y1 = trimfuzz
in
2819 invalidate "settrim"
2821 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2826 match state.throttle
with
2828 let zoom = max
0.0001 zoom in
2829 if zoom <> conf.zoom
2831 state.prevzoom
<- conf.zoom;
2833 reshape state.winw
state.winh
;
2834 state.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
2837 | Some
(layout, y, started
) ->
2839 match conf.maxwait
with
2843 let dt = now () -. started
in
2851 let setcolumns mode columns coverA coverB
=
2852 state.prevcolumns
<- Some
(conf.columns
, conf.zoom);
2856 then showtext '
!'
"split mode doesn't work in bird's eye"
2858 conf.columns
<- Csplit
(-columns
, [||]);
2866 conf.columns
<- Csingle
[||];
2871 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2875 reshape state.winw
state.winh
;
2878 let enterbirdseye () =
2879 let zoom = float conf.thumbw
/. float state.winw
in
2880 let birdseyepageno =
2881 let cy = state.winh
/ 2 in
2885 let rec fold best
= function
2888 let d = cy - (l.pagedispy + l.pagevh/2)
2889 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2890 if abs
d < abs dbest
2897 state.mode
<- Birdseye
(
2898 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2901 conf.presentation
<- false;
2902 conf.interpagespace
<- 10;
2903 conf.hlinks
<- false;
2904 conf.fitmodel
<- FitProportional
;
2906 state.mstate
<- Mnone
;
2907 conf.maxwait
<- None
;
2909 match conf.beyecolumns
with
2912 Cmulti
((c, 0, 0), [||])
2913 | None
-> Csingle
[||]
2915 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2918 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2923 reshape state.winw
state.winh
;
2926 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2928 conf.zoom <- c.zoom;
2929 conf.presentation
<- c.presentation
;
2930 conf.interpagespace
<- c.interpagespace
;
2931 conf.maxwait
<- c.maxwait
;
2932 conf.hlinks
<- c.hlinks
;
2933 conf.fitmodel
<- c.fitmodel
;
2934 conf.beyecolumns
<- (
2935 match conf.columns
with
2936 | Cmulti
((c, _, _), _) -> Some
c
2938 | Csplit
_ -> failwith
"leaving bird's eye split mode"
2941 match c.columns
with
2942 | Cmulti
(c, _) -> Cmulti
(c, [||])
2943 | Csingle
_ -> Csingle
[||]
2944 | Csplit
(c, _) -> Csplit
(c, [||])
2949 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2952 reshape state.winw
state.winh
;
2953 state.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
2956 let togglebirdseye () =
2957 match state.mode
with
2958 | Birdseye vals
-> leavebirdseye vals
true
2959 | View
-> enterbirdseye ()
2963 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2964 let pageno = max
0 (pageno - incr
) in
2965 let rec loop = function
2966 | [] -> gotopage1 pageno 0
2967 | l :: _ when l.pageno = pageno ->
2968 if l.pagedispy >= 0 && l.pagey = 0
2969 then G.postRedisplay "upbirdseye"
2970 else gotopage1 pageno 0
2971 | _ :: rest
-> loop rest
2974 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2977 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2978 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2979 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2980 let rec loop = function
2982 let y, h = getpageyh pageno in
2983 let dy = (y - state.y) - (state.winh
- h - conf.interpagespace
) in
2985 | l :: _ when l.pageno = pageno ->
2986 if l.pagevh != l.pageh
2987 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace
))
2988 else G.postRedisplay "downbirdseye"
2989 | _ :: rest
-> loop rest
2994 let optentry mode
_ key =
2995 let btos b = if b then "on" else "off" in
2996 if key >= 32 && key < 127
2998 let c = Char.chr
key in
3002 try conf.scrollstep
<- int_of_string
s with exc
->
3003 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3005 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
3010 conf.autoscrollstep
<- int_of_string
s;
3011 if state.autoscroll
<> None
3012 then state.autoscroll
<- Some
conf.autoscrollstep
3014 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3016 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
3021 let n, a, b = multicolumns_of_string s in
3022 setcolumns mode
n a b;
3024 state.text <- Printf.sprintf
"bad columns `%s': %s" s (exntos exc
)
3026 TEswitch
("columns: ", "", None
, textentry, ondone, true)
3031 let zoom = float (int_of_string
s) /. 100.0 in
3034 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3036 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
3041 conf.thumbw
<- bound (int_of_string
s) 2 4096;
3043 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
3044 begin match mode
with
3046 leavebirdseye beye
false;
3051 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3053 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
3058 Some
(int_of_string
s)
3060 state.text <- Printf.sprintf
"bad integer `%s': %s"
3064 | Some angle
-> reqlayout angle
conf.fitmodel
3067 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
3070 conf.icase
<- not
conf.icase
;
3071 TEdone
("case insensitive search " ^
(btos conf.icase
))
3074 conf.preload <- not
conf.preload;
3076 TEdone
("preload " ^
(btos conf.preload))
3079 conf.verbose
<- not
conf.verbose
;
3080 TEdone
("verbose " ^
(btos conf.verbose
))
3083 conf.debug
<- not
conf.debug
;
3084 TEdone
("debug " ^
(btos conf.debug
))
3087 conf.maxhfit
<- not
conf.maxhfit
;
3088 state.maxy
<- calcheight ();
3089 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
3092 conf.crophack
<- not
conf.crophack
;
3093 TEdone
("crophack " ^
btos conf.crophack
)
3097 match conf.maxwait
with
3099 conf.maxwait
<- Some infinity
;
3100 "always wait for page to complete"
3102 conf.maxwait
<- None
;
3103 "show placeholder if page is not ready"
3108 conf.underinfo
<- not
conf.underinfo
;
3109 TEdone
("underinfo " ^
btos conf.underinfo
)
3112 conf.savebmarks
<- not
conf.savebmarks
;
3113 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
3119 match state.layout with
3124 conf.interpagespace
<- int_of_string
s;
3125 docolumns conf.columns
;
3126 state.maxy
<- calcheight ();
3127 let y = getpagey pageno in
3130 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
)
3132 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
3136 match conf.fitmodel
with
3137 | FitProportional
-> FitWidth
3138 | _ -> FitProportional
3140 reqlayout conf.angle
fm;
3141 TEdone
("proportional display " ^
btos (fm == FitProportional
))
3144 settrim (not
conf.trimmargins
) conf.trimfuzz
;
3145 TEdone
("trim margins " ^
btos conf.trimmargins
)
3148 conf.invert
<- not
conf.invert
;
3149 TEdone
("invert colors " ^
btos conf.invert
)
3153 cbput state.hists
.sel
s;
3156 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
3157 textentry, ondone, true)
3160 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
3166 class type lvsource
= object
3167 method getitemcount
: int
3168 method getitem
: int -> (string * int)
3169 method hasaction
: int -> bool
3178 method getactive
: int
3179 method getfirst
: int
3180 method getqsearch
: string
3181 method setqsearch
: string -> unit
3185 class virtual lvsourcebase
= object
3186 val mutable m_active
= 0
3187 val mutable m_first
= 0
3188 val mutable m_qsearch
= ""
3189 val mutable m_pan
= 0
3190 method getactive
= m_active
3191 method getfirst
= m_first
3192 method getqsearch
= m_qsearch
3193 method getpan
= m_pan
3194 method setqsearch
s = m_qsearch
<- s
3197 let withoutlastutf8 s =
3198 let len = String.length
s in
3206 let b = Char.code
s.[pos
] in
3207 if b land 0b11000000 = 0b11000000
3212 if Char.code
s.[len-1] land 0x80 = 0
3216 String.sub
s 0 first;
3219 let textentrykeyboard
3220 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
3222 if key >= 0xffb0 && key <= 0xffb9
3223 then key - 0xffb0 + 48 else key
3226 state.mode
<- Textentry
(te
, onleave
);
3229 G.postRedisplay "textentrykeyboard enttext";
3231 let histaction cmd
=
3234 | Some
(action, _) ->
3235 state.mode
<- Textentry
(
3236 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
3238 G.postRedisplay "textentry histaction"
3241 | 0xff08 -> (* backspace *)
3242 let s = withoutlastutf8 text in
3243 let len = String.length
s in
3244 if cancelonempty
&& len = 0
3247 G.postRedisplay "textentrykeyboard after cancel";
3250 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3253 | 0xff0d | 0xff8d -> (* (kp) enter *)
3256 G.postRedisplay "textentrykeyboard after confirm"
3258 | 0xff52 | 0xff97 -> histaction HCprev
(* (kp) up *)
3259 | 0xff54 | 0xff99 -> histaction HCnext
(* (kp) down *)
3260 | 0xff50 | 0xff95 -> histaction HCfirst
(* (kp) home) *)
3261 | 0xff57 | 0xff9c -> histaction HClast
(* (kp) end *)
3263 | 0xff1b -> (* escape*)
3264 if String.length
text = 0
3266 begin match opthist
with
3268 | Some
(_, onhistcancel
) -> onhistcancel
()
3272 G.postRedisplay "textentrykeyboard after cancel2"
3275 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3278 | 0xff9f | 0xffff -> () (* delete *)
3281 && key land 0xff00 != 0xff00 (* keyboard *)
3282 && key land 0xfe00 != 0xfe00 (* xkb *)
3283 && key land 0xfd00 != 0xfd00 (* 3270 *)
3285 begin match onkey
text key with
3289 G.postRedisplay "textentrykeyboard after confirm2";
3292 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3296 G.postRedisplay "textentrykeyboard after cancel3"
3299 state.mode
<- Textentry
(te
, onleave
);
3300 G.postRedisplay "textentrykeyboard switch";
3304 vlog "unhandled key %s" (Wsi.keyname
key)
3307 let firstof first active
=
3308 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3309 then max
0 (active
- (fstate.maxrows
/2))
3313 let calcfirst first active
=
3316 let rows = active
- first in
3317 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3321 let scrollph y maxy
=
3322 let sh = float (maxy
+ state.winh
) /. float state.winh
in
3323 let sh = float state.winh
/. sh in
3324 let sh = max
sh (float conf.scrollh
) in
3326 let percent = float y /. float maxy
in
3327 let position = (float state.winh
-. sh) *. percent in
3330 if position +. sh > float state.winh
3331 then float state.winh
-. sh
3337 let coe s = (s :> uioh
);;
3339 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3341 val m_pan
= source#getpan
3342 val m_first
= source#getfirst
3343 val m_active
= source#getactive
3344 val m_qsearch
= source#getqsearch
3345 val m_prev_uioh
= state.uioh
3347 method private elemunder
y =
3348 let n = y / (fstate.fontsize
+1) in
3349 if m_first
+ n < source#getitemcount
3351 if source#hasaction
(m_first
+ n)
3352 then Some
(m_first
+ n)
3359 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3360 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3361 GlDraw.rect (0., 0.) (float state.winw
, float state.winh
);
3362 GlDraw.color
(1., 1., 1.);
3363 Gl.enable `texture_2d
;
3364 let fs = fstate.fontsize
in
3366 let ww = fstate.wwidth
in
3367 let tabw = 30.0*.ww in
3368 let itemcount = source#getitemcount
in
3370 if (row - m_first
) > fstate.maxrows
3373 if row >= 0 && row < itemcount
3375 let (s, level
) = source#getitem
row in
3376 let y = (row - m_first
) * nfs in
3377 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3380 Gl.disable `texture_2d
;
3381 GlDraw.polygon_mode `both `line
;
3382 let alpha = if source#hasaction
row then 0.9 else 0.3 in
3383 GlDraw.color
(1., 1., 1.) ~
alpha;
3384 GlDraw.rect (1., float (y + 1))
3385 (float (state.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3386 GlDraw.polygon_mode `both `fill
;
3387 GlDraw.color
(1., 1., 1.);
3388 Gl.enable `texture_2d
;
3391 let drawtabularstring s =
3392 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3395 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3398 let len = String.length
s - tabpos - 1 in
3399 let s1 = String.sub
s 0 tabpos
3400 and s2
= String.sub
s (tabpos + 1) len in
3401 let nx = drawstr x s1 in
3403 let x = x +. (max
tabw sw) in
3410 let _ = drawtabularstring s in
3417 Gl.disable `texture_2d
;
3419 method updownlevel incr
=
3420 let len = source#getitemcount
in
3422 if m_active
>= 0 && m_active
< len
3423 then snd
(source#getitem m_active
)
3427 if i
= len then i
-1 else if i
= -1 then 0 else
3428 let _, l = source#getitem i
in
3429 if l != curlevel then i
else flow (i
+incr
)
3431 let active = flow m_active
in
3432 let first = calcfirst m_first
active in
3433 G.postRedisplay "outline updownlevel";
3434 {< m_active
= active; m_first
= first >}
3436 method private key1
key mask
=
3437 let set1 active first qsearch
=
3438 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3440 let search active pattern incr
=
3441 let active = if active = -1 then m_first
else active in
3444 if n >= 0 && n < source#getitemcount
3446 let s, _ = source#getitem
n in
3448 (try ignore
(Str.search_forward
re s 0); true
3449 with Not_found
-> false)
3451 else loop (n + incr
)
3458 let re = Str.regexp_case_fold pattern
in
3464 let itemcount = source#getitemcount
in
3465 let find start incr
=
3467 if i
= -1 || i
= itemcount
3470 if source#hasaction i
3472 else find (i
+ incr
)
3477 let set active first =
3478 let first = bound first 0 (itemcount - fstate.maxrows
) in
3480 coe {< m_active
= active; m_first
= first; m_qsearch
= "" >}
3483 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3485 let incr1 = if incr
> 0 then 1 else -1 in
3486 if isvisible m_first m_active
3489 let next = m_active
+ incr
in
3491 if next < 0 || next >= itemcount
3493 else find next incr1
3495 if abs
(m_active
- next) > fstate.maxrows
3501 let first = m_first
+ incr
in
3502 let first = bound first 0 (itemcount - fstate.maxrows
) in
3504 let next = m_active
+ incr
in
3505 let next = bound next 0 (itemcount - 1) in
3512 if isvisible first next
3519 let first = min
next m_first
in
3521 if abs
(next - first) > fstate.maxrows
3527 let first = m_first
+ incr
in
3528 let first = bound first 0 (itemcount - 1) in
3530 let next = m_active
+ incr
in
3531 let next = bound next 0 (itemcount - 1) in
3532 let next = find next incr1 in
3534 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3536 let active = if m_active
= -1 then next else m_active
in
3541 if isvisible first active
3547 G.postRedisplay "listview navigate";
3551 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3552 let incr = if key = 0x72 then -1 else 1 in
3554 match search (m_active
+ incr) m_qsearch
incr with
3556 state.text <- m_qsearch ^
" [not found]";
3559 state.text <- m_qsearch
;
3560 active, firstof m_first
active
3562 G.postRedisplay "listview ctrl-r/s";
3563 set1 active first m_qsearch
;
3565 | 0xff63 when Wsi.withctrl mask
-> (* ctrl-insert *)
3566 if m_active
>= 0 && m_active
< source#getitemcount
3568 let s, _ = source#getitem m_active
in
3573 | 0xff08 -> (* backspace *)
3574 if String.length m_qsearch
= 0
3577 let qsearch = withoutlastutf8 m_qsearch
in
3578 let len = String.length
qsearch in
3582 G.postRedisplay "listview empty qsearch";
3583 set1 m_active m_first
"";
3587 match search m_active
qsearch ~
-1 with
3589 state.text <- qsearch ^
" [not found]";
3592 state.text <- qsearch;
3593 active, firstof m_first
active
3595 G.postRedisplay "listview backspace qsearch";
3596 set1 active first qsearch
3599 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3600 let pattern = m_qsearch ^ toutf8
key in
3602 match search m_active
pattern 1 with
3604 state.text <- pattern ^
" [not found]";
3607 state.text <- pattern;
3608 active, firstof m_first
active
3610 G.postRedisplay "listview qsearch add";
3611 set1 active first pattern;
3613 | 0xff1b -> (* escape *)
3615 if String.length m_qsearch
= 0
3617 G.postRedisplay "list view escape";
3620 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3622 | None
-> m_prev_uioh
3627 G.postRedisplay "list view kill qsearch";
3628 source#setqsearch
"";
3629 coe {< m_qsearch
= "" >}
3632 | 0xff0d | 0xff8d -> (* (kp) enter *)
3634 let self = {< m_qsearch
= "" >} in
3635 source#setqsearch
"";
3637 G.postRedisplay "listview enter";
3638 if m_active
>= 0 && m_active
< source#getitemcount
3640 source#exit
(coe self) false m_active m_first m_pan
"";
3643 source#exit
(coe self) true m_active m_first m_pan
"";
3646 begin match opt with
3647 | None
-> m_prev_uioh
3651 | 0xff9f | 0xffff -> (* (kp) delete *)
3654 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3655 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3656 | 0xff55 | 0xff9a -> navigate ~
-(fstate.maxrows
) (* (kp) prior *)
3657 | 0xff56 | 0xff9b -> navigate fstate.maxrows
(* (kp) next *)
3659 | 0xff53 | 0xff98 -> (* (kp) right *)
3661 G.postRedisplay "listview right";
3662 coe {< m_pan
= m_pan
- 1 >}
3664 | 0xff51 | 0xff96 -> (* (kp) left *)
3666 G.postRedisplay "listview left";
3667 coe {< m_pan
= m_pan
+ 1 >}
3669 | 0xff50 | 0xff95 -> (* (kp) home *)
3670 let active = find 0 1 in
3671 G.postRedisplay "listview home";
3674 | 0xff57 | 0xff9c -> (* (kp) end *)
3675 let first = max
0 (itemcount - fstate.maxrows
) in
3676 let active = find (itemcount - 1) ~
-1 in
3677 G.postRedisplay "listview end";
3680 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3684 dolog
"listview unknown key %#x" key; coe self
3686 method key key mask
=
3687 match state.mode
with
3688 | Textentry te
-> textentrykeyboard key mask te
; coe self
3689 | _ -> self#key1
key mask
3691 method button button down
x y _ =
3694 | 1 when x > state.winw
- conf.scrollbw
->
3695 G.postRedisplay "listview scroll";
3698 let _, position, sh = self#
scrollph in
3699 if y > truncate
position && y < truncate
(position +. sh)
3701 state.mstate
<- Mscrolly
;
3705 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3706 let first = truncate
(s *. float source#getitemcount
) in
3707 let first = min source#getitemcount
first in
3708 Some
(coe {< m_first
= first; m_active
= first >})
3710 state.mstate
<- Mnone
;
3713 | 1 when not down
->
3714 begin match self#elemunder
y with
3716 G.postRedisplay "listview click";
3718 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3722 | n when (n == 4 || n == 5) && not down
->
3723 let len = source#getitemcount
in
3725 if n = 5 && m_first
+ fstate.maxrows
>= len
3729 let first = m_first
+ (if n == 4 then -1 else 1) in
3730 bound first 0 (len - 1)
3732 G.postRedisplay "listview wheel";
3733 Some
(coe {< m_first
= first >})
3734 | n when (n = 6 || n = 7) && not down
->
3735 let inc = m_first
+ (if n = 7 then -1 else 1) in
3736 G.postRedisplay "listview hwheel";
3737 Some
(coe {< m_pan
= m_pan
+ inc >})
3742 | None
-> m_prev_uioh
3746 match state.mstate
with
3748 let s = float (max
0 (y - conf.scrollh
)) /. float state.winh
in
3749 let first = truncate
(s *. float source#getitemcount
) in
3750 let first = min source#getitemcount
first in
3751 G.postRedisplay "listview motion";
3752 coe {< m_first
= first; m_active
= first >}
3755 method pmotion
x y =
3756 if x < state.winw
- conf.scrollbw
3759 match self#elemunder
y with
3760 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3761 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3765 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3770 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3774 method infochanged
_ = ()
3776 method scrollpw
= (0, 0.0, 0.0)
3778 let nfs = fstate.fontsize
+ 1 in
3779 let y = m_first
* nfs in
3780 let itemcount = source#getitemcount
in
3781 let maxi = max
0 (itemcount - fstate.maxrows
) in
3782 let maxy = maxi * nfs in
3783 let p, h = scrollph y maxy in
3786 method modehash
= modehash
3787 method eformsgs
= false
3790 class outlinelistview ~source
=
3793 ~source
:(source
:> lvsource
)
3795 ~modehash
:(findkeyhash conf "outline")
3798 method key key mask
=
3799 let calcfirst first active =
3802 let rows = active - first in
3804 if String.length
state.text = 0
3806 else fstate.maxrows - 2
3808 if rows > maxrows then active - maxrows else first
3812 let active = m_active
+ incr in
3813 let active = bound active 0 (source#getitemcount
- 1) in
3814 let first = calcfirst m_first
active in
3815 G.postRedisplay "outline navigate";
3816 coe {< m_active
= active; m_first
= first >}
3818 let ctrl = Wsi.withctrl mask
in
3820 | 110 when ctrl -> (* ctrl-n *)
3821 source#narrow m_qsearch
;
3822 G.postRedisplay "outline ctrl-n";
3823 coe {< m_first
= 0; m_active
= 0 >}
3825 | 117 when ctrl -> (* ctrl-u *)
3827 G.postRedisplay "outline ctrl-u";
3829 coe {< m_first
= 0; m_active
= 0 >}
3831 | 108 when ctrl -> (* ctrl-l *)
3832 let first = max
0 (m_active
- (fstate.maxrows / 2)) in
3833 G.postRedisplay "outline ctrl-l";
3834 coe {< m_first
= first >}
3836 | 0xff9f | 0xffff -> (* (kp) delete *)
3837 source#remove m_active
;
3838 G.postRedisplay "outline delete";
3839 let active = max
0 (m_active
-1) in
3840 coe {< m_first
= firstof m_first
active;
3841 m_active
= active >}
3843 | 0xff52 | 0xff97 -> navigate ~
-1 (* (kp) up *)
3844 | 0xff54 | 0xff99 -> navigate 1 (* (kp) down *)
3845 | 0xff55 | 0xff9a -> (* (kp) prior *)
3846 navigate ~
-(fstate.maxrows)
3847 | 0xff56 | 0xff9b -> (* (kp) next *)
3848 navigate fstate.maxrows
3850 | 0xff53 | 0xff98 -> (* [ctrl-] (kp) right *)
3854 G.postRedisplay "outline ctrl right";
3855 {< m_pan
= m_pan
+ 1 >}
3857 else self#updownlevel
1
3861 | 0xff51 | 0xff96 -> (* [ctrl-] (kp) left *)
3865 G.postRedisplay "outline ctrl left";
3866 {< m_pan
= m_pan
- 1 >}
3868 else self#updownlevel ~
-1
3872 | 0xff50 | 0xff95 -> (* (kp) home *)
3873 G.postRedisplay "outline home";
3874 coe {< m_first
= 0; m_active
= 0 >}
3876 | 0xff57 | 0xff9c -> (* (kp) end *)
3877 let active = source#getitemcount
- 1 in
3878 let first = max
0 (active - fstate.maxrows) in
3879 G.postRedisplay "outline end";
3880 coe {< m_active
= active; m_first
= first >}
3882 | _ -> super#
key key mask
3885 let outlinesource usebookmarks
=
3888 inherit lvsourcebase
3889 val mutable m_items
= empty
3890 val mutable m_orig_items
= empty
3891 val mutable m_prev_items
= empty
3892 val mutable m_narrow_pattern
= ""
3893 val mutable m_hadremovals
= false
3895 method getitemcount
=
3896 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3899 if n == Array.length m_items
&& m_hadremovals
3901 ("[Confirm removal]", 0)
3903 let s, n, _ = m_items
.(n) in
3906 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3907 ignore
(uioh
, first, qsearch);
3908 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3910 if String.length m_narrow_pattern
= 0
3916 if not
confrimremoval
3918 let _, _, anchor = m_items
.(active) in
3919 gotoghyll (getanchory anchor);
3923 state.bookmarks
<- Array.to_list m_items
;
3924 m_orig_items
<- m_items
;
3927 else m_items
<- items;
3931 method hasaction
_ = true
3934 if Array.length m_items
!= Array.length m_orig_items
3935 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3938 method narrow
pattern =
3939 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3943 let rec loop accu n =
3946 m_narrow_pattern
<- pattern;
3947 m_items
<- Array.of_list
accu
3950 let (s, _, _) as o = m_items
.(n) in
3952 if (try ignore
(Str.search_forward
re s 0); true
3953 with Not_found
-> false)
3959 loop [] (Array.length m_items
- 1)
3964 then Array.of_list
state.bookmarks
3967 m_items
<- m_orig_items
3972 if m >= 0 && m < Array.length m_items
3974 m_hadremovals
<- true;
3975 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3976 let n = if n >= m then n+1 else n in
3981 method reset
anchor items =
3982 m_hadremovals
<- false;
3983 if m_orig_items
== empty || m_prev_items
!= items
3985 m_orig_items
<- items;
3986 if String.length m_narrow_pattern
= 0
3987 then m_items
<- items;
3989 m_prev_items
<- items;
3990 let rely = getanchory anchor in
3992 let rec loop n best bestd
=
3993 if n = Array.length m_items
3996 let (_, _, anchor) = m_items
.(n) in
3997 let orely = getanchory anchor in
3998 let d = abs
(orely - rely) in
4001 else loop (n+1) best bestd
4006 m_first
<- firstof m_first
active
4010 let enterselector usebookmarks
=
4011 let source = outlinesource usebookmarks
in
4015 then Array.of_list
state.bookmarks
4018 if Array.length
outlines = 0
4020 showtext ' ' errmsg
;
4023 state.text <- source#greetmsg
;
4024 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4025 let anchor = getanchor () in
4026 source#reset
anchor outlines;
4027 state.uioh
<- coe (new outlinelistview ~
source);
4028 G.postRedisplay "enter selector";
4032 let enteroutlinemode =
4033 let f = enterselector false in
4034 fun ()-> f "Document has no outline";
4037 let enterbookmarkmode =
4038 let f = enterselector true in
4039 fun () -> f "Document has no bookmarks (yet)";
4042 let color_of_string s =
4043 Scanf.sscanf
s "%d/%d/%d" (fun r g b ->
4044 (float r /. 256.0, float g /. 256.0, float b /. 256.0)
4048 let color_to_string (r, g, b) =
4049 let r = truncate
(r *. 256.0)
4050 and g = truncate
(g *. 256.0)
4051 and b = truncate
(b *. 256.0) in
4052 Printf.sprintf
"%d/%d/%d" r g b
4055 let irect_of_string s =
4056 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
4059 let irect_to_string (x0,y0,x1,y1) =
4060 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
4063 let makecheckers () =
4064 (* Based on lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
4066 converted by Issac Trotts. July 25, 2002 *)
4067 let image = GlPix.create `ubyte ~format
:`luminance ~width
:2 ~height
:2 in
4068 Raw.sets_string
(GlPix.to_raw
image) ~pos
:0 "\255\200\200\255";
4069 let id = GlTex.gen_texture
() in
4070 GlTex.bind_texture `texture_2d
id;
4071 GlPix.store
(`unpack_alignment
1);
4072 GlTex.image2d
image;
4073 List.iter
(GlTex.parameter ~target
:`texture_2d
)
4074 [ `mag_filter `nearest
; `min_filter `nearest
];
4078 let setcheckers enabled
=
4079 match state.texid
with
4081 if enabled
then state.texid
<- Some
(makecheckers ())
4086 GlTex.delete_texture texid
;
4087 state.texid
<- None
;
4091 let int_of_string_with_suffix s =
4092 let l = String.length
s in
4096 let suffix = Char.lowercase
s.[l-1] in
4098 | 'k'
-> String.sub
s 0 (l-1), 10
4099 | '
m'
-> String.sub
s 0 (l-1), 20
4100 | '
g'
-> String.sub
s 0 (l-1), 30
4104 let n = int_of_string
s1 in
4105 let m = n lsl shift
in
4107 then raise
(Failure
"value too large")
4111 let string_with_suffix_of_int n =
4116 if n land ((1 lsl 30) - 1) = 0
4119 if n land ((1 lsl 20) - 1) = 0
4122 if n land ((1 lsl 10) - 1) = 0
4129 let h = n mod 1000 in
4132 then string_of_int
h ^
s
4134 let s = Printf.sprintf
"_%03d%s" h s in
4141 let defghyllscroll = (40, 8, 32);;
4142 let ghyllscroll_of_string s =
4143 let (n, a, b) as nab
=
4146 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
4148 if n <= a || n <= b || a >= b
4149 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
4153 let ghyllscroll_to_string ((n, a, b) as nab
) =
4154 if nab
= defghyllscroll
4156 else Printf.sprintf
"%d,%d,%d" n a b;
4159 let describe_location () =
4160 let fn = page_of_y state.y in
4161 let ln = page_of_y (state.y + state.winh
- hscrollh () - 1) in
4162 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
4166 else (100. *. (float state.y /. float maxy))
4170 Printf.sprintf
"page %d of %d [%.2f%%]"
4171 (fn+1) state.pagecount
percent
4174 "pages %d-%d of %d [%.2f%%]"
4175 (fn+1) (ln+1) state.pagecount
percent
4178 let setpresentationmode v
=
4179 let n = page_of_y state.y in
4180 state.anchor <- (n, 0.0, 1.0);
4181 conf.presentation
<- v
;
4182 if conf.fitmodel
= FitPage
4183 then reqlayout conf.angle
conf.fitmodel
;
4188 let btos b = if b then "\xe2\x88\x9a" else "" in
4189 let showextended = ref false in
4190 let leave mode
= function
4191 | Confirm
-> state.mode
<- mode
4192 | Cancel
-> state.mode
<- mode
in
4195 val mutable m_first_time
= true
4196 val mutable m_l
= []
4197 val mutable m_a
= [||]
4198 val mutable m_prev_uioh
= nouioh
4199 val mutable m_prev_mode
= View
4201 inherit lvsourcebase
4203 method reset prev_mode prev_uioh
=
4204 m_a
<- Array.of_list
(List.rev m_l
);
4206 m_prev_mode
<- prev_mode
;
4207 m_prev_uioh
<- prev_uioh
;
4211 if n >= Array.length m_a
4215 | _, _, _, Action
_ -> m_active
<- n
4219 m_first_time
<- false;
4222 method int name get
set =
4224 (name
, `
int get
, 1, Action
(
4227 try set (int_of_string
s)
4229 state.text <- Printf.sprintf
"bad integer `%s': %s"
4233 let te = name ^
": ", "", None
, intentry, ondone, true in
4234 state.mode
<- Textentry
(te, leave m_prev_mode
);
4238 method int_with_suffix name get
set =
4240 (name
, `intws get
, 1, Action
(
4243 try set (int_of_string_with_suffix s)
4245 state.text <- Printf.sprintf
"bad integer `%s': %s"
4250 name ^
": ", "", None
, intentry_with_suffix, ondone, true
4252 state.mode
<- Textentry
(te, leave m_prev_mode
);
4256 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
4258 (name
, `
bool (btos, get
), offset
, Action
(
4265 method color name get
set =
4267 (name
, `color get
, 1, Action
(
4269 let invalid = (nan
, nan
, nan
) in
4272 try color_of_string s
4274 state.text <- Printf.sprintf
"bad color `%s': %s"
4281 let te = name ^
": ", "", None
, textentry, ondone, true in
4282 state.text <- color_to_string (get
());
4283 state.mode
<- Textentry
(te, leave m_prev_mode
);
4287 method string name get
set =
4289 (name
, `
string get
, 1, Action
(
4291 let ondone s = set s in
4292 let te = name ^
": ", "", None
, textentry, ondone, true in
4293 state.mode
<- Textentry
(te, leave m_prev_mode
);
4297 method colorspace name get
set =
4299 (name
, `
string get
, 1, Action
(
4302 let vals = [| "rgb"; "bgr"; "gray" |] in
4304 inherit lvsourcebase
4307 m_active
<- int_of_colorspace conf.colorspace
;
4310 method getitemcount
= Array.length
vals
4311 method getitem
n = (vals.(n), 0)
4312 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4313 ignore
(uioh
, first, pan
, qsearch);
4314 if not cancel
then set active;
4316 method hasaction
_ = true
4320 let modehash = findkeyhash conf "info" in
4321 coe (new listview ~
source ~trusted
:true ~
modehash)
4324 method fitmodel name get
set =
4326 (name
, `
string get
, 1, Action
(
4329 let vals = [| "fit width"; "proportional"; "fit page" |] in
4331 inherit lvsourcebase
4334 m_active
<- int_of_fitmodel conf.fitmodel
;
4337 method getitemcount
= Array.length
vals
4338 method getitem
n = (vals.(n), 0)
4339 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4340 ignore
(uioh
, first, pan
, qsearch);
4341 if not cancel
then set active;
4343 method hasaction
_ = true
4347 let modehash = findkeyhash conf "info" in
4348 coe (new listview ~
source ~trusted
:true ~
modehash)
4351 method caption
s offset
=
4352 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4354 method caption2
s f offset
=
4355 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4357 method getitemcount
= Array.length m_a
4360 let tostr = function
4361 | `
int f -> string_of_int
(f ())
4362 | `intws
f -> string_with_suffix_of_int (f ())
4364 | `color
f -> color_to_string (f ())
4365 | `
bool (btos, f) -> btos (f ())
4368 let name, t
, offset
, _ = m_a
.(n) in
4369 ((let s = tostr t
in
4370 if String.length
s > 0
4371 then Printf.sprintf
"%s\t%s" name s
4375 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4379 m_qsearch
<- qsearch;
4381 match m_a
.(active) with
4382 | _, _, _, Action
f -> f uioh
4394 method hasaction
n =
4396 | _, _, _, Action
_ -> true
4400 let rec fillsrc prevmode prevuioh
=
4401 let sep () = src#caption
"" 0 in
4402 let colorp name get
set =
4404 (fun () -> color_to_string (get
()))
4407 let c = color_of_string v in
4410 state.text <- Printf.sprintf
"bad color `%s': %s" v (exntos exn
)
4413 let oldmode = state.mode
in
4414 let birdseye = isbirdseye state.mode
in
4416 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4418 src#
bool "presentation mode"
4419 (fun () -> conf.presentation
)
4420 (fun v -> setpresentationmode v);
4422 src#
bool "ignore case in searches"
4423 (fun () -> conf.icase
)
4424 (fun v -> conf.icase
<- v);
4427 (fun () -> conf.preload)
4428 (fun v -> conf.preload <- v);
4430 src#
bool "highlight links"
4431 (fun () -> conf.hlinks
)
4432 (fun v -> conf.hlinks
<- v);
4434 src#
bool "under info"
4435 (fun () -> conf.underinfo
)
4436 (fun v -> conf.underinfo
<- v);
4438 src#
bool "persistent bookmarks"
4439 (fun () -> conf.savebmarks
)
4440 (fun v -> conf.savebmarks
<- v);
4442 src#fitmodel
"fit model"
4443 (fun () -> fitmodel_to_string conf.fitmodel
)
4444 (fun v -> reqlayout conf.angle
(fitmodel_of_int v));
4446 src#
bool "trim margins"
4447 (fun () -> conf.trimmargins
)
4448 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4450 src#
bool "persistent location"
4451 (fun () -> conf.jumpback
)
4452 (fun v -> conf.jumpback
<- v);
4455 src#
int "inter-page space"
4456 (fun () -> conf.interpagespace
)
4458 conf.interpagespace
<- n;
4459 docolumns conf.columns
;
4461 match state.layout with
4466 state.maxy <- calcheight ();
4467 let y = getpagey pageno in
4472 (fun () -> conf.pagebias
)
4473 (fun v -> conf.pagebias
<- v);
4475 src#
int "scroll step"
4476 (fun () -> conf.scrollstep
)
4477 (fun n -> conf.scrollstep
<- n);
4479 src#
int "horizontal scroll step"
4480 (fun () -> conf.hscrollstep
)
4481 (fun v -> conf.hscrollstep
<- v);
4483 src#
int "auto scroll step"
4485 match state.autoscroll
with
4487 | _ -> conf.autoscrollstep
)
4489 if state.autoscroll
<> None
4490 then state.autoscroll
<- Some
n;
4491 conf.autoscrollstep
<- n);
4494 (fun () -> truncate
(conf.zoom *. 100.))
4495 (fun v -> setzoom ((float v) /. 100.));
4498 (fun () -> conf.angle
)
4499 (fun v -> reqlayout v conf.fitmodel
);
4501 src#
int "scroll bar width"
4502 (fun () -> conf.scrollbw
)
4505 reshape state.winw
state.winh
;
4508 src#
int "scroll handle height"
4509 (fun () -> conf.scrollh
)
4510 (fun v -> conf.scrollh
<- v;);
4512 src#
int "thumbnail width"
4513 (fun () -> conf.thumbw
)
4515 conf.thumbw
<- min
4096 v;
4518 leavebirdseye beye
false;
4523 let mode = state.mode in
4524 src#
string "columns"
4526 match conf.columns
with
4528 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4529 | Csplit
(count
, _) -> "-" ^ string_of_int count
4532 let n, a, b = multicolumns_of_string v in
4533 setcolumns mode n a b);
4536 src#caption
"Pixmap cache" 0;
4537 src#int_with_suffix
"size (advisory)"
4538 (fun () -> conf.memlimit
)
4539 (fun v -> conf.memlimit
<- v);
4542 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4543 (string_with_suffix_of_int state.memused
)
4544 (Hashtbl.length
state.tilemap
)) 1;
4547 src#caption
"Layout" 0;
4548 src#caption2
"Dimension"
4550 Printf.sprintf
"%dx%d (virtual %dx%d)"
4551 state.winw
state.winh
4556 src#caption2
"Position" (fun () ->
4557 Printf.sprintf
"%dx%d" state.x state.y
4560 src#caption2
"Position" (fun () -> describe_location ()) 1
4564 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4565 "Save these parameters as global defaults at exit"
4566 (fun () -> conf.bedefault
)
4567 (fun v -> conf.bedefault
<- v)
4571 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4572 src#
bool ~offset
:0 ~
btos "Extended parameters"
4573 (fun () -> !showextended)
4574 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4578 (fun () -> conf.checkers
)
4579 (fun v -> conf.checkers
<- v; setcheckers v);
4580 src#
bool "update cursor"
4581 (fun () -> conf.updatecurs
)
4582 (fun v -> conf.updatecurs
<- v);
4584 (fun () -> conf.verbose
)
4585 (fun v -> conf.verbose
<- v);
4586 src#
bool "invert colors"
4587 (fun () -> conf.invert
)
4588 (fun v -> conf.invert
<- v);
4590 (fun () -> conf.maxhfit
)
4591 (fun v -> conf.maxhfit
<- v);
4592 src#
bool "redirect stderr"
4593 (fun () -> conf.redirectstderr)
4594 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4595 src#
string "uri launcher"
4596 (fun () -> conf.urilauncher
)
4597 (fun v -> conf.urilauncher
<- v);
4598 src#
string "path launcher"
4599 (fun () -> conf.pathlauncher
)
4600 (fun v -> conf.pathlauncher
<- v);
4601 src#
string "tile size"
4602 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4605 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4606 conf.tilew
<- max
64 w;
4607 conf.tileh
<- max
64 h;
4610 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4613 src#
int "texture count"
4614 (fun () -> conf.texcount
)
4617 then conf.texcount
<- v
4618 else showtext '
!'
" Failed to set texture count please retry later"
4620 src#
int "slice height"
4621 (fun () -> conf.sliceheight
)
4623 conf.sliceheight
<- v;
4624 wcmd "sliceh %d" conf.sliceheight
;
4626 src#
int "anti-aliasing level"
4627 (fun () -> conf.aalevel
)
4629 conf.aalevel
<- bound v 0 8;
4630 state.anchor <- getanchor ();
4631 opendoc state.path
state.password
;
4633 src#
string "page scroll scaling factor"
4634 (fun () -> string_of_float
conf.pgscale)
4637 let s = float_of_string
v in
4640 state.text <- Printf.sprintf
4641 "bad page scroll scaling factor `%s': %s" v (exntos exn
)
4644 src#
int "ui font size"
4645 (fun () -> fstate.fontsize
)
4646 (fun v -> setfontsize (bound v 5 100));
4647 src#
int "hint font size"
4648 (fun () -> conf.hfsize
)
4649 (fun v -> conf.hfsize
<- bound v 5 100);
4650 colorp "background color"
4651 (fun () -> conf.bgcolor
)
4652 (fun v -> conf.bgcolor
<- v);
4653 src#
bool "crop hack"
4654 (fun () -> conf.crophack
)
4655 (fun v -> conf.crophack
<- v);
4656 src#
string "trim fuzz"
4657 (fun () -> irect_to_string conf.trimfuzz
)
4660 conf.trimfuzz
<- irect_of_string v;
4662 then settrim true conf.trimfuzz
;
4664 state.text <- Printf.sprintf
"bad irect `%s': %s" v (exntos exn
)
4666 src#
string "throttle"
4668 match conf.maxwait
with
4669 | None
-> "show place holder if page is not ready"
4672 then "wait for page to fully render"
4674 "wait " ^ string_of_float
time
4675 ^
" seconds before showing placeholder"
4679 let f = float_of_string
v in
4681 then conf.maxwait
<- None
4682 else conf.maxwait
<- Some
f
4684 state.text <- Printf.sprintf
"bad time `%s': %s" v (exntos exn
)
4686 src#
string "ghyll scroll"
4688 match conf.ghyllscroll
with
4690 | Some nab
-> ghyllscroll_to_string nab
4695 if String.length
v = 0
4697 else Some
(ghyllscroll_of_string v)
4699 conf.ghyllscroll
<- gs
4701 state.text <- Printf.sprintf
"bad ghyll `%s': %s" v (exntos exn
)
4703 src#
string "selection command"
4704 (fun () -> conf.selcmd
)
4705 (fun v -> conf.selcmd
<- v);
4706 src#
string "synctex command"
4707 (fun () -> conf.stcmd
)
4708 (fun v -> conf.stcmd
<- v);
4709 src#colorspace
"color space"
4710 (fun () -> colorspace_to_string conf.colorspace
)
4712 conf.colorspace
<- colorspace_of_int v;
4719 (fun () -> conf.usepbo
)
4720 (fun v -> conf.usepbo
<- v);
4721 src#
bool "mouse wheel scrolls pages"
4722 (fun () -> conf.wheelbypage
)
4723 (fun v -> conf.wheelbypage
<- v);
4724 src#
bool "open remote links in a new instance"
4725 (fun () -> conf.riani
)
4726 (fun v -> conf.riani
<- v);
4730 src#caption
"Document" 0;
4731 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4732 src#caption2
"Pages"
4733 (fun () -> string_of_int
state.pagecount
) 1;
4734 src#caption2
"Dimensions"
4735 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4739 src#caption
"Trimmed margins" 0;
4740 src#caption2
"Dimensions"
4741 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4745 src#caption
"OpenGL" 0;
4746 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
4747 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
4750 src#caption
"Location" 0;
4751 if String.length
state.origin
> 0
4752 then src#caption
("Orign\t" ^ mbtoutf8
state.origin
) 1;
4753 src#caption
("Path\t" ^ mbtoutf8
state.path
) 1;
4755 src#reset prevmode prevuioh
;
4759 let prevmode = state.mode
4760 and prevuioh
= state.uioh in
4761 fillsrc prevmode prevuioh
;
4762 let source = (src :> lvsource
) in
4763 let modehash = findkeyhash conf "info" in
4764 state.uioh <- coe (object (self)
4765 inherit listview ~
source ~trusted
:true ~
modehash as super
4766 val mutable m_prevmemused
= 0
4767 method infochanged
= function
4769 if m_prevmemused
!= state.memused
4771 m_prevmemused
<- state.memused
;
4772 G.postRedisplay "memusedchanged";
4774 | Pdim
-> G.postRedisplay "pdimchanged"
4775 | Docinfo
-> fillsrc prevmode prevuioh
4777 method key key mask
=
4778 if not
(Wsi.withctrl mask
)
4781 | 0xff51 | 0xff96 -> coe (self#updownlevel ~
-1) (* (kp) left *)
4782 | 0xff53 | 0xff98 -> coe (self#updownlevel
1) (* (kp) right *)
4783 | _ -> super#
key key mask
4784 else super#
key key mask
4786 G.postRedisplay "info";
4792 inherit lvsourcebase
4793 method getitemcount
= Array.length
state.help
4795 let s, l, _ = state.help
.(n) in
4798 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4802 m_qsearch
<- qsearch;
4803 match state.help
.(active) with
4804 | _, _, Action
f -> Some
(f uioh)
4814 method hasaction
n =
4815 match state.help
.(n) with
4816 | _, _, Action
_ -> true
4823 let modehash = findkeyhash conf "help" in
4824 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4825 G.postRedisplay "help";
4830 let re = Str.regexp
"[\r\n]" in
4832 inherit lvsourcebase
4833 val mutable m_items
= [||]
4835 method getitemcount
= 1 + Array.length m_items
4840 else m_items
.(n-1), 0
4842 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4847 then Buffer.clear
state.errmsgs
;
4848 m_qsearch
<- qsearch;
4855 method hasaction
n =
4859 state.newerrmsgs
<- false;
4860 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4861 m_items
<- Array.of_list
l
4869 let source = (msgsource :> lvsource
) in
4870 let modehash = findkeyhash conf "listview" in
4871 state.uioh <- coe (object
4872 inherit listview ~
source ~trusted
:false ~
modehash as super
4875 then msgsource#reset
;
4878 G.postRedisplay "msgs";
4881 let quickbookmark ?title
() =
4882 match state.layout with
4888 let sec = Unix.gettimeofday
() in
4889 let tm = Unix.localtime
sec in
4890 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4894 (tm.Unix.tm_year
+ 1900)
4897 | Some
title -> title
4899 state.bookmarks
<- (title, 0, getanchor1 l) :: state.bookmarks
4902 let setautoscrollspeed step goingdown
=
4903 let incr = max
1 ((abs step
) / 2) in
4904 let incr = if goingdown
then incr else -incr in
4905 let astep = step
+ incr in
4906 state.autoscroll
<- Some
astep;
4909 let gotounder = function
4910 | Ulinkgoto
(pageno, top) ->
4914 gotopage1 pageno top;
4920 | Uremote
(filename
, pageno) ->
4922 if String.length filename
> 0
4924 if Filename.is_relative filename
4926 let dir = Filename.dirname
state.path in
4928 if Filename.is_implicit
dir
4929 then Filename.concat
(Sys.getcwd
()) dir
4932 Filename.concat
dir filename
4937 if Sys.file_exists
path
4941 if String.length
path > 0
4945 let command = !selfexec ^
" " ^
path in
4946 try popen command []
4949 "failed to execute `%s': %s\n" command (exntos exn
);
4952 let anchor = getanchor () in
4953 let ranchor = state.path, state.password
, anchor, state.origin
in
4955 state.anchor <- (pageno, 0.0, 0.0);
4956 state.ranchors
<- ranchor :: state.ranchors
;
4959 else showtext '
!'
("Could not find " ^ filename
)
4961 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4965 match conf.columns
with
4967 | _ -> state.x != 0 || conf.zoom > 1.0
4970 let panbound x = bound x (-state.w) (wadjsb state.winw
);;
4972 let existsinrow pageno (columns
, coverA
, coverB
) p =
4973 let last = ((pageno - coverA
) mod columns
) + columns
in
4974 let rec any = function
4977 if l.pageno = coverA
- 1 || l.pageno = state.pagecount
- coverB
4981 then (if l.pageno = last then false else any rest
)
4989 match state.layout with
4991 let pageno = page_of_y state.y in
4992 gotoghyll (getpagey (pageno+1))
4994 match conf.columns
with
4996 if conf.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
4998 let y = clamp (pgscale state.winh
) in
5001 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
5002 gotoghyll (getpagey pageno)
5003 | Cmulti
((c, _, _) as cl, _) ->
5004 if conf.presentation
5005 && (existsinrow l.pageno cl
5006 (fun l -> l.pageh
> l.pagey + l.pagevh))
5008 let y = clamp (pgscale state.winh
) in
5011 let pageno = min
(l.pageno+c) (state.pagecount
-1) in
5012 gotoghyll (getpagey pageno)
5014 if l.pageno < state.pagecount
- 1 || l.pagecol
< n - 1
5016 let pagey, pageh
= getpageyh l.pageno in
5017 let pagey = pagey + pageh
* l.pagecol
in
5018 let ips = if l.pagecol
= 0 then 0 else conf.interpagespace
in
5019 gotoghyll (pagey + pageh
+ ips)
5023 match state.layout with
5025 let pageno = page_of_y state.y in
5026 gotoghyll (getpagey (pageno-1))
5028 match conf.columns
with
5030 if conf.presentation
&& l.pagey != 0
5032 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5034 let pageno = max
0 (l.pageno-1) in
5035 gotoghyll (getpagey pageno)
5036 | Cmulti
((c, _, coverB
) as cl, _) ->
5037 if conf.presentation
&&
5038 (existsinrow l.pageno cl (fun l -> l.pagey != 0))
5040 gotoghyll (clamp (pgscale ~
-(state.winh
)))
5043 if l.pageno = state.pagecount
- coverB
5047 let pageno = max
0 (l.pageno-decr) in
5048 gotoghyll (getpagey pageno)
5056 let pageno = max
0 (l.pageno-1) in
5057 let pagey, pageh
= getpageyh pageno in
5060 let pagey, pageh
= getpageyh l.pageno in
5061 pagey + pageh
* (l.pagecol
-1) - conf.interpagespace
5066 let viewkeyboard key mask
=
5068 let mode = state.mode in
5069 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
5072 G.postRedisplay "view:enttext"
5074 let ctrl = Wsi.withctrl mask
in
5076 if key >= 0xffb0 && key < 0xffb9 then key - 0xffb0 + 48 else key
5082 | 0xff63 -> (* insert *)
5083 if conf.angle
mod 360 = 0 && not
(isbirdseye state.mode)
5085 state.mode <- LinkNav
(Ltgendir
0);
5088 else showtext '
!'
"Keyboard link navigation does not work under rotation"
5090 | 0xff1b | 113 -> (* escape / q *)
5091 begin match state.mstate
with
5093 state.mstate
<- Mnone
;
5094 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5095 G.postRedisplay "kill zoom rect";
5097 begin match state.mode with
5100 G.postRedisplay "esc leave linknav"
5102 match state.ranchors
with
5104 | (path, password
, anchor, origin
) :: rest
->
5105 state.ranchors
<- rest
;
5106 state.anchor <- anchor;
5107 state.origin
<- origin
;
5108 opendoc path password
5112 | 0xff08 -> (* backspace *)
5113 gotoghyll (getnav ~
-1)
5121 G.postRedisplay "dehighlight";
5123 | 47 | 63 -> (* / ? *)
5124 let ondone isforw
s =
5125 cbput state.hists
.pat
s;
5126 state.searchpattern
<- s;
5129 let s = String.create
1 in
5130 s.[0] <- Char.chr
key;
5131 enttext (s, "", Some
(onhist state.hists
.pat
),
5132 textentry, ondone (key = 47), true)
5134 | 43 | 0xffab | 61 when ctrl -> (* ctrl-+ or ctrl-= *)
5135 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
5136 setzoom (conf.zoom +. incr)
5138 | 43 | 0xffab -> (* + *)
5141 try int_of_string
s with exc
->
5142 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5148 state.text <- "page bias is now " ^ string_of_int
n;
5151 enttext ("page bias: ", "", None
, intentry, ondone, true)
5153 | 45 | 0xffad when ctrl -> (* ctrl-- *)
5154 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
5155 setzoom (max
0.01 (conf.zoom -. decr))
5157 | 45 | 0xffad -> (* - *)
5158 let ondone msg
= state.text <- msg
in
5160 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
5161 optentry state.mode, ondone, true
5164 | 48 when ctrl -> (* ctrl-0 *)
5172 | (49 | 50) when ctrl && conf.fitmodel
!= FitPage
-> (* ctrl-1/2 *)
5174 match conf.columns
with
5175 | Csingle
_ | Cmulti
_ -> 1
5176 | Csplit
(n, _) -> n
5178 let h = state.winh
-
5179 conf.interpagespace
lsl (if conf.presentation
then 1 else 0)
5181 let zoom = zoomforh
state.winw
h (vscrollw ()) cols in
5182 if zoom > 0.0 && (key = 50 || zoom < 1.0)
5185 | 51 when ctrl -> (* ctrl-3 *)
5187 match conf.fitmodel
with
5188 | FitWidth
-> FitProportional
5189 | FitProportional
-> FitPage
5190 | FitPage
-> FitWidth
5192 state.text <- "fit model: " ^
fitmodel_to_string fm;
5193 reqlayout conf.angle
fm
5195 | 0xffc6 -> (* f9 *)
5198 | 57 when ctrl -> (* ctrl-9 *)
5201 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
5202 when not
ctrl -> (* 0..9 *)
5205 try int_of_string
s with exc
->
5206 state.text <- Printf.sprintf
"bad integer `%s': %s" s (exntos exc
);
5212 cbput state.hists
.pag
(string_of_int
n);
5213 gotopage1 (n + conf.pagebias
- 1) 0;
5216 let pageentry text key =
5217 match Char.unsafe_chr
key with
5218 | '
g'
-> TEdone
text
5219 | _ -> intentry text key
5221 let text = "x" in text.[0] <- Char.chr
key;
5222 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
5225 conf.scrollb
<- if conf.scrollb
= 0 then (scrollbvv lor scrollbhv) else 0;
5226 reshape state.winw
state.winh
;
5229 conf.hlinks
<- not
conf.hlinks
;
5230 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
5231 G.postRedisplay "toggle highlightlinks";
5234 state.glinks
<- true;
5235 let mode = state.mode in
5236 state.mode <- Textentry
(
5237 (":", "", None
, linknentry, linkndone gotounder, false),
5239 state.glinks
<- false;
5243 G.postRedisplay "view:linkent(F)"
5246 state.glinks
<- true;
5247 let mode = state.mode in
5248 state.mode <- Textentry
(
5250 ":", "", None
, linknentry, linkndone (fun under ->
5251 selstring (undertext under);
5255 state.glinks
<- false;
5259 G.postRedisplay "view:linkent"
5262 begin match state.autoscroll
with
5264 conf.autoscrollstep
<- step
;
5265 state.autoscroll
<- None
5267 if conf.autoscrollstep
= 0
5268 then state.autoscroll
<- Some
1
5269 else state.autoscroll
<- Some
conf.autoscrollstep
5272 | 112 when ctrl -> (* ctrl-p *)
5276 setpresentationmode (not
conf.presentation
);
5277 showtext ' '
("presentation mode " ^
5278 if conf.presentation
then "on" else "off");
5281 if List.mem
Wsi.Fullscreen
state.winstate
5282 then Wsi.reshape conf.cwinw
conf.cwinh
5283 else Wsi.fullscreen
()
5285 | 112 | 78 -> (* p|N *)
5286 search state.searchpattern
false
5288 | 110 | 0xffc0 -> (* n|F3 *)
5289 search state.searchpattern
true
5292 begin match state.layout with
5295 gotoghyll (getpagey l.pageno)
5301 | 0xff9f | 0xffff -> (* delete *)
5305 showtext ' '
(describe_location ());
5308 begin match state.layout with
5311 Wsi.reshape (l.pagew
+ vscrollw ()) l.pageh
;
5316 enterbookmarkmode ()
5318 | 104 | 0xffbe -> (* h|F1 *)
5324 | 101 when Buffer.length
state.errmsgs
> 0 -> (* e *)
5329 match state.layout with
5331 if String.length
s > 0
5333 state.bookmarks
<- (s, 0, getanchor1 l) :: state.bookmarks
5336 enttext ("bookmark: ", "", None
, textentry, ondone, true)
5340 showtext ' '
"Quick bookmark added";
5343 begin match state.layout with
5345 let rect = getpdimrect
l.pagedimno
in
5349 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
5350 truncate
(1.2 *. (rect.(3) -. rect.(0))))
5352 (truncate
(rect.(1) -. rect.(0)),
5353 truncate
(rect.(3) -. rect.(0)))
5355 let w = truncate
((float w)*.conf.zoom)
5356 and h = truncate
((float h)*.conf.zoom) in
5359 state.anchor <- getanchor ();
5360 Wsi.reshape (w + vscrollw ()) (h + conf.interpagespace
)
5362 G.postRedisplay "z";
5367 | 60 | 62 -> (* < > *)
5368 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.fitmodel
5370 | 91 | 93 -> (* [ ] *)
5372 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5374 G.postRedisplay "brightness";
5376 | 99 when state.mode = View
-> (* [alt]-c *)
5381 let m = (wadjsb state.winw
- state.w) / 2 in
5383 gotoy_and_clear_text state.y
5387 match state.prevcolumns
with
5388 | None
-> (1, 0, 0), 1.0
5389 | Some
(columns
, z
) ->
5392 | Csplit
(c, _) -> -c, 0, 0
5393 | Cmulti
((c, a, b), _) -> c, a, b
5394 | Csingle
_ -> 1, 0, 0
5398 setcolumns View
c a b;
5401 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5402 setzoom state.prevzoom
5404 | 107 | 0xff52 | 0xff97 -> (* k (kp) up *)
5405 begin match state.autoscroll
with
5407 begin match state.mode with
5408 | Birdseye beye
-> upbirdseye 1 beye
5411 then gotoy_and_clear_text (clamp ~
-(state.winh
/2))
5413 if not
(Wsi.withshift mask
) && conf.presentation
5415 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5419 setautoscrollspeed n false
5422 | 106 | 0xff54 | 0xff99 -> (* j (kp) down *)
5423 begin match state.autoscroll
with
5425 begin match state.mode with
5426 | Birdseye beye
-> downbirdseye 1 beye
5429 then gotoy_and_clear_text (clamp (state.winh
/2))
5431 if not
(Wsi.withshift mask
) && conf.presentation
5433 else gotoy_and_clear_text (clamp conf.scrollstep
)
5437 setautoscrollspeed n true
5440 | 0xff51 | 0xff53 | 0xff96 | 0xff98
5441 when not
(Wsi.withalt mask
) -> (* (kp) left / right *)
5447 else conf.hscrollstep
5449 let dx = if key = 0xff51 or key = 0xff96 then dx else -dx in
5450 state.x <- panbound (state.x + dx);
5451 gotoy_and_clear_text state.y
5454 G.postRedisplay "left/right"
5457 | 0xff55 | 0xff9a -> (* (kp) prior *)
5461 match state.layout with
5463 | l :: _ -> state.y - l.pagey
5465 clamp (pgscale (-state.winh
))
5469 | 0xff56 | 0xff9b -> (* (kp) next *)
5473 match List.rev
state.layout with
5475 | l :: _ -> getpagey l.pageno
5477 clamp (pgscale state.winh
)
5481 | 103 | 0xff50 | 0xff95 -> (* g (kp) home *)
5483 | 71 | 0xff57 | 0xff9c -> (* G (kp) end *)
5484 gotoghyll (clamp state.maxy)
5487 when Wsi.withalt mask
-> (* alt-(kp) right *)
5488 gotoghyll (getnav 1)
5490 when Wsi.withalt mask
-> (* alt-(kp) left *)
5491 gotoghyll (getnav ~
-1)
5496 | 118 when conf.debug
-> (* v *)
5499 match getopaque l.pageno with
5502 let x0, y0, x1, y1 = pagebbox opaque
in
5503 let a,b = float x0, float y0 in
5504 let c,d = float x1, float y0 in
5505 let e,f = float x1, float y1 in
5506 let h,j
= float x0, float y1 in
5507 let rect = (a,b,c,d,e,f,h,j
) in
5509 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5511 G.postRedisplay "v";
5514 vlog "huh? %s" (Wsi.keyname
key)
5517 let linknavkeyboard key mask
linknav =
5518 let getpage pageno =
5519 let rec loop = function
5521 | l :: _ when l.pageno = pageno -> Some
l
5522 | _ :: rest
-> loop rest
5523 in loop state.layout
5525 let doexact (pageno, n) =
5526 match getopaque pageno, getpage pageno with
5527 | Some opaque
, Some
l ->
5528 if key = 0xff0d || key = 0xff8d (* (kp)enter *)
5530 let under = getlink opaque
n in
5531 G.postRedisplay "link gotounder";
5537 | 0xff50 -> (* home *)
5538 Some
(findlink opaque LDfirst
), -1
5540 | 0xff57 -> (* end *)
5541 Some
(findlink opaque LDlast
), 1
5543 | 0xff51 -> (* left *)
5544 Some
(findlink opaque
(LDleft
n)), -1
5546 | 0xff53 -> (* right *)
5547 Some
(findlink opaque
(LDright
n)), 1
5549 | 0xff52 -> (* up *)
5550 Some
(findlink opaque
(LDup
n)), -1
5552 | 0xff54 -> (* down *)
5553 Some
(findlink opaque
(LDdown
n)), 1
5558 begin match findpwl
l.pageno dir with
5562 state.mode <- LinkNav
(Ltgendir
dir);
5563 let y, h = getpageyh pageno in
5566 then y + h - state.winh
5571 begin match getopaque pageno, getpage pageno with
5572 | Some opaque
, Some
_ ->
5574 let ld = if dir > 0 then LDfirst
else LDlast
in
5577 begin match link with
5579 showlinktype (getlink opaque
m);
5580 state.mode <- LinkNav
(Ltexact
(pageno, m));
5581 G.postRedisplay "linknav jpage";
5588 begin match opt with
5589 | Some Lnotfound
-> pwl l dir;
5590 | Some
(Lfound
m) ->
5594 let _, y0, _, y1 = getlinkrect opaque
m in
5596 then gotopage1 l.pageno y0
5598 let d = fstate.fontsize
+ 1 in
5599 if y1 - l.pagey > l.pagevh - d
5600 then gotopage1 l.pageno (y1 - state.winh
- hscrollh () + d)
5601 else G.postRedisplay "linknav";
5603 showlinktype (getlink opaque
m);
5604 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5607 | None
-> viewkeyboard key mask
5609 | _ -> viewkeyboard key mask
5614 G.postRedisplay "leave linknav"
5618 | Ltgendir
_ -> viewkeyboard key mask
5619 | Ltexact exact
-> doexact exact
5622 let keyboard key mask
=
5623 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5624 then wcmd "interrupt"
5625 else state.uioh <- state.uioh#
key key mask
5628 let birdseyekeyboard key mask
5629 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5631 match conf.columns
with
5633 | Cmulti
((c, _, _), _) -> c
5634 | Csplit
_ -> failwith
"bird's eye split mode"
5636 let pgh layout = List.fold_left
(fun m l -> max
l.pageh
m) state.winh
layout in
5638 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5639 let y, h = getpageyh pageno in
5640 let top = (state.winh
- h) / 2 in
5641 gotoy (max
0 (y - top))
5642 | 0xff0d (* enter *)
5643 | 0xff8d -> leavebirdseye beye
false (* kp enter *)
5644 | 0xff1b -> leavebirdseye beye
true (* escape *)
5645 | 0xff52 -> upbirdseye incr beye
(* up *)
5646 | 0xff54 -> downbirdseye incr beye
(* down *)
5647 | 0xff51 -> upbirdseye 1 beye
(* left *)
5648 | 0xff53 -> downbirdseye 1 beye
(* right *)
5650 | 0xff55 -> (* prior *)
5651 begin match state.layout with
5655 state.mode <- Birdseye
(
5656 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5658 gotopage1 l.pageno 0;
5661 let layout = layout (state.y-state.winh
) (pgh state.layout) in
5663 | [] -> gotoy (clamp (-state.winh
))
5665 state.mode <- Birdseye
(
5666 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5668 gotopage1 l.pageno 0
5671 | [] -> gotoy (clamp (-state.winh
))
5674 | 0xff56 -> (* next *)
5675 begin match List.rev
state.layout with
5677 let layout = layout (state.y + (pgh state.layout)) state.winh
in
5678 begin match layout with
5680 let incr = l.pageh
- l.pagevh in
5685 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5687 G.postRedisplay "birdseye pagedown";
5689 else gotoy (clamp (incr + conf.interpagespace
*2));
5693 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5694 gotopage1 l.pageno 0;
5697 | [] -> gotoy (clamp state.winh
)
5700 | 0xff50 -> (* home *)
5701 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5704 | 0xff57 -> (* end *)
5705 let pageno = state.pagecount
- 1 in
5706 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5707 if not
(pagevisible state.layout pageno)
5710 match List.rev
state.pdims
with
5712 | (_, _, h, _) :: _ -> h
5714 gotoy (max
0 (getpagey pageno - (state.winh
- h - conf.interpagespace
)))
5715 else G.postRedisplay "birdseye end";
5716 | _ -> viewkeyboard key mask
5721 match state.mode with
5722 | Textentry
_ -> scalecolor 0.4
5724 | View
-> scalecolor 1.0
5725 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5726 if l.pageno = hooverpageno
5729 if l.pageno = pageno
5737 let postdrawpage l linkindexbase
=
5738 match getopaque l.pageno with
5740 if tileready l l.pagex
l.pagey
5742 let x = l.pagedispx - l.pagex
5743 and y = l.pagedispy - l.pagey in
5745 match conf.columns
with
5746 | Csingle
_ | Cmulti
_ ->
5747 (if conf.hlinks
then 1 else 0)
5749 && not
(isbirdseye state.mode) then 2 else 0)
5753 match state.mode with
5754 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5757 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5762 let scrollindicator () =
5763 let sbw, ph
, sh = state.uioh#
scrollph in
5764 let sbh, pw, sw = state.uioh#scrollpw
in
5766 GlDraw.color (0.64, 0.64, 0.64);
5768 (float (state.winw
- sbw), 0.)
5769 (float state.winw
, float state.winh
)
5772 (0., float (state.winh
- sbh))
5773 (float (wadjsb state.winw
- 1), float state.winh
)
5775 GlDraw.color (0.0, 0.0, 0.0);
5778 (float (state.winw
- sbw), ph
)
5779 (float state.winw
, ph
+. sh)
5782 (pw, float (state.winh
- sbh))
5783 (pw +. sw, float state.winh
)
5788 match state.mstate
with
5789 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5792 | Msel
((x0, y0), (x1, y1)) ->
5793 let rec loop = function
5795 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5796 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5797 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5798 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5800 match getopaque l.pageno with
5802 let x0, y0 = pagetranslatepoint l x0 y0 in
5803 let x1, y1 = pagetranslatepoint l x1 y1 in
5804 seltext opaque
(x0, y0, x1, y1);
5812 let showrects rects
=
5814 GlDraw.color (0.0, 0.0, 1.0) ~
alpha:0.5;
5815 GlDraw.polygon_mode `both `fill
;
5816 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5818 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5820 if l.pageno = pageno
5822 let dx = float (l.pagedispx - l.pagex
) in
5823 let dy = float (l.pagedispy - l.pagey) in
5824 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~
alpha:0.5;
5825 GlDraw.begins `quads
;
5827 GlDraw.vertex2
(x0+.dx, y0+.dy);
5828 GlDraw.vertex2
(x1+.dx, y1+.dy);
5829 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5830 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5841 GlClear.color (scalecolor2 conf.bgcolor
);
5842 GlClear.clear
[`
color];
5843 List.iter
drawpage state.layout;
5845 match state.mode with
5846 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5847 begin match getopaque pageno with
5849 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5856 | None
-> state.rects
5861 let rec postloop linkindexbase
= function
5863 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
5864 postloop linkindexbase rest
5868 postloop 0 state.layout;
5870 begin match state.mstate
with
5871 | Mzoomrect
((x0, y0), (x1, y1)) ->
5873 GlDraw.color (0.3, 0.3, 0.3) ~
alpha:0.5;
5874 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5875 GlDraw.rect (float x0, float y0)
5876 (float x1, float y1);
5885 let zoomrect x y x1 y1 =
5888 and y0 = min
y y1 in
5889 gotoy (state.y + y0);
5890 state.anchor <- getanchor ();
5891 let zoom = (float state.w) /. float (x1 - x0) in
5893 match conf.fitmodel
, conf.columns
with
5894 | FitPage
, Csplit
_ ->
5895 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
5898 let adjw = wadjsb state.winw
in
5900 then (adjw - state.w) / 2
5903 state.x <- (state.x + margin) - x0;
5905 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5906 state.mstate
<- Mnone
;
5910 let winw = wadjsb state.winw - 1 in
5911 let s = float x /. float winw in
5912 let destx = truncate
(float (state.w + winw) *. s) in
5913 state.x <- winw - destx;
5914 gotoy_and_clear_text state.y;
5915 state.mstate
<- Mscrollx
;
5919 let s = float y /. float state.winh
in
5920 let desty = truncate
(float (state.maxy - state.winh
) *. s) in
5921 gotoy_and_clear_text desty;
5922 state.mstate
<- Mscrolly
;
5925 let viewmouse button down
x y mask
=
5927 | n when (n == 4 || n == 5) && not down
->
5928 if Wsi.withctrl mask
5930 match state.mstate
with
5931 | Mzoom
(oldn
, i
) ->
5939 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5941 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5943 let zoom = conf.zoom -. incr in
5945 state.mstate
<- Mzoom
(n, 0);
5947 state.mstate
<- Mzoom
(n, i
+1);
5949 else state.mstate
<- Mzoom
(n, 0)
5951 | _ -> state.mstate
<- Mzoom
(n, 0)
5954 match state.autoscroll
with
5955 | Some step
-> setautoscrollspeed step
(n=4)
5957 if conf.wheelbypage
|| conf.presentation
5966 then -conf.scrollstep
5967 else conf.scrollstep
5969 let incr = incr * 2 in
5970 let y = clamp incr in
5971 gotoy_and_clear_text y
5974 | n when (n = 6 || n = 7) && not down
&& canpan () ->
5976 panbound (state.x + (if n = 7 then -2 else 2) * conf.hscrollstep
);
5977 gotoy_and_clear_text state.y
5979 | 1 when Wsi.withshift mask
->
5980 state.mstate
<- Mnone
;
5983 match unproject x y with
5984 | Some
(pageno, ux
, uy
) ->
5985 let cmd = Printf.sprintf
5987 conf.stcmd
state.path pageno ux uy
5993 | 1 when Wsi.withctrl mask
->
5996 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5997 state.mstate
<- Mpan
(x, y)
6000 state.mstate
<- Mnone
6005 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
6007 state.mstate
<- Mzoomrect
(p, p)
6010 match state.mstate
with
6011 | Mzoomrect
((x0, y0), _) ->
6012 if abs
(x-x0) > 10 && abs
(y - y0) > 10
6013 then zoomrect x0 y0 x y
6015 state.mstate
<- Mnone
;
6016 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6017 G.postRedisplay "kill accidental zoom rect";
6020 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6021 state.mstate
<- Mnone
6024 | 1 when x > state.winw - vscrollw () ->
6027 let _, position, sh = state.uioh#
scrollph in
6028 if y > truncate
position && y < truncate
(position +. sh)
6029 then state.mstate
<- Mscrolly
6032 state.mstate
<- Mnone
6034 | 1 when y > state.winh
- hscrollh () ->
6037 let _, position, sw = state.uioh#scrollpw
in
6038 if x > truncate
position && x < truncate
(position +. sw)
6039 then state.mstate
<- Mscrollx
6042 state.mstate
<- Mnone
6045 let dest = if down
then getunder x y else Unone
in
6046 begin match dest with
6050 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
6053 | Unone
when down
->
6054 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
6055 state.mstate
<- Mpan
(x, y);
6057 | Unone
| Utext
_ ->
6060 if conf.angle
mod 360 = 0
6062 state.mstate
<- Msel
((x, y), (x, y));
6063 G.postRedisplay "mouse select";
6067 match state.mstate
with
6070 | Mzoom
_ | Mscrollx
| Mscrolly
->
6071 state.mstate
<- Mnone
6073 | Mzoomrect
((x0, y0), _) ->
6077 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6078 state.mstate
<- Mnone
6080 | Msel
((x0, y0), (x1, y1)) ->
6081 let rec loop = function
6085 let a0 = l.pagedispy in
6086 let a1 = a0 + l.pagevh in
6087 let b0 = l.pagedispx in
6088 let b1 = b0 + l.pagevw in
6089 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
6090 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
6094 match getopaque l.pageno with
6097 match Ne.pipe () with
6101 "can not create sel pipe: %s"
6104 let doclose what fd
=
6105 Ne.clo fd
(fun msg
->
6106 dolog
"%s close failed: %s" what msg
)
6109 popen conf.selcmd
[r, 0; w, -1];
6112 G.postRedisplay "copysel";
6114 dolog
"can not execute %S: %s"
6115 conf.selcmd
(exntos exn
);
6123 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
6124 state.mstate
<- Mnone
;
6131 let birdseyemouse button down
x y mask
6132 (conf, leftx
, _, hooverpageno
, anchor) =
6135 let rec loop = function
6138 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6139 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6141 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
6147 | _ -> viewmouse button down
x y mask
6150 let mouse button down
x y mask
=
6151 state.uioh <- state.uioh#button button down
x y mask
;
6155 state.uioh <- state.uioh#
motion x y
6159 state.uioh <- state.uioh#
pmotion x y;
6165 method key key mask
=
6166 begin match state.mode with
6167 | Textentry
textentry -> textentrykeyboard key mask
textentry
6168 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
6169 | View
-> viewkeyboard key mask
6170 | LinkNav
linknav -> linknavkeyboard key mask
linknav
6174 method button button bstate
x y mask
=
6175 begin match state.mode with
6177 | View
-> viewmouse button bstate
x y mask
6178 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
6184 begin match state.mode with
6186 | View
| Birdseye
_ | LinkNav
_ ->
6187 match state.mstate
with
6188 | Mzoom
_ | Mnone
-> ()
6193 state.mstate
<- Mpan
(x, y);
6195 then state.x <- panbound (state.x + dx);
6197 gotoy_and_clear_text y
6200 state.mstate
<- Msel
(a, (x, y));
6201 G.postRedisplay "motion select";
6204 let y = min
state.winh
(max
0 y) in
6208 let x = min
state.winw (max
0 x) in
6211 | Mzoomrect
(p0
, _) ->
6212 state.mstate
<- Mzoomrect
(p0
, (x, y));
6213 G.postRedisplay "motion zoomrect";
6217 method pmotion x y =
6218 begin match state.mode with
6219 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
6220 let rec loop = function
6222 if hooverpageno
!= -1
6224 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
6225 G.postRedisplay "pmotion birdseye no hoover";
6228 if y > l.pagedispy && y < l.pagedispy + l.pagevh
6229 && x > l.pagedispx && x < l.pagedispx + l.pagevw
6231 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
6232 G.postRedisplay "pmotion birdseye hoover";
6242 match state.mstate
with
6243 | Mnone
-> updateunder x y
6244 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
6249 method infochanged
_ = ()
6252 let maxy = state.maxy - (if conf.maxhfit
then state.winh
else 0) in
6255 then 0.0, float state.winh
6256 else scrollph state.y maxy
6261 let winw = wadjsb state.winw in
6262 let fwinw = float winw in
6264 let sw = fwinw /. float state.w in
6265 let sw = fwinw *. sw in
6266 max
sw (float conf.scrollh
)
6269 let maxx = state.w + winw in
6270 let x = winw - state.x in
6271 let percent = float x /. float maxx in
6272 (fwinw -. sw) *. percent
6274 hscrollh (), position, sw
6278 match state.mode with
6279 | LinkNav
_ -> "links"
6280 | Textentry
_ -> "textentry"
6281 | Birdseye
_ -> "birdseye"
6284 findkeyhash conf modename
6286 method eformsgs
= true
6293 let fontpath = ref "";;
6296 Map.Make
(struct type t
= (int * int) let compare = compare end);;
6299 let l = String.length
s in
6300 let b = Buffer.create
l in
6306 try Sys.getenv
"HOME"
6309 ("Can not determine home directory location: " ^ exntos exn
);
6313 let modifier_of_string = function
6314 | "alt" -> Wsi.altmask
6315 | "shift" -> Wsi.shiftmask
6316 | "ctrl" | "control" -> Wsi.ctrlmask
6317 | "meta" -> Wsi.metamask
6322 let r = Str.regexp
"-" in
6324 let elems = Str.full_split
r s in
6327 let m1 = modifier_of_string s in
6329 then (Wsi.namekey
s, m)
6332 | Str.Delim
s when n land 1 = 0 -> g s
6334 | Str.Delim
_ -> (k
, m)
6336 let rec loop n k
m = function
6339 let k, m = f n k m x in
6345 let keys_of_string =
6346 let r = Str.regexp
"[ \t]" in
6348 let elems = Str.split
r s in
6349 List.map
key_of_string elems
6352 let copykeyhashes c =
6353 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
6356 let config_of c attrs
=
6360 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
6361 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
6362 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
6363 | "preload" -> { c with preload = bool_of_string
v }
6364 | "page-bias" -> { c with pagebias
= int_of_string
v }
6365 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
6366 | "horizontal-scroll-step" ->
6367 { c with hscrollstep
= max
(int_of_string
v) 1 }
6368 | "auto-scroll-step" ->
6369 { c with autoscrollstep
= max
0 (int_of_string
v) }
6370 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
6371 | "crop-hack" -> { c with crophack
= bool_of_string
v }
6374 match String.lowercase
v with
6375 | "true" -> Some infinity
6377 | f -> Some
(float_of_string
f)
6379 { c with maxwait
= mw}
6380 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
6381 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
6382 | "vertical-margin" ->
6383 { c with interpagespace
= max
0 (int_of_string
v) }
6385 let zoom = float_of_string
v /. 100. in
6386 let zoom = max
zoom 0.0 in
6387 { c with zoom = zoom }
6388 | "presentation" -> { c with presentation
= bool_of_string
v }
6389 | "rotation-angle" -> { c with angle
= int_of_string
v }
6390 | "width" -> { c with cwinw
= max
20 (int_of_string
v) }
6391 | "height" -> { c with cwinh
= max
20 (int_of_string
v) }
6392 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
6393 | "proportional-display" ->
6396 then FitProportional
6399 { c with fitmodel
= fm }
6400 | "fit-model" -> { c with fitmodel
= fitmodel_of_string v }
6401 | "pixmap-cache-size" ->
6402 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
6403 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
6404 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
6405 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
6406 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
6407 | "background-color" -> { c with bgcolor
= color_of_string v }
6408 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
6409 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
6410 | "mupdf-store-size" ->
6411 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
6412 | "checkers" -> { c with checkers
= bool_of_string
v }
6413 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
6414 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
6415 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
6416 | "uri-launcher" -> { c with urilauncher
= unent v }
6417 | "path-launcher" -> { c with pathlauncher
= unent v }
6418 | "color-space" -> { c with colorspace
= colorspace_of_string v }
6419 | "invert-colors" -> { c with invert
= bool_of_string
v }
6420 | "brightness" -> { c with colorscale
= float_of_string
v }
6421 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
6423 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
6425 let (n, _, _) as nab
= multicolumns_of_string v in
6427 then { c with columns
= Csplit
(-n, [||]) }
6428 else { c with columns
= Cmulti
(nab
, [||]) }
6429 | "birds-eye-columns" ->
6430 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
6431 | "selection-command" -> { c with selcmd
= unent v }
6432 | "synctex-command" -> { c with stcmd
= unent v }
6433 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
6434 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
6435 | "page-scroll-scale" -> { c with pgscale = float_of_string
v }
6436 | "use-pbo" -> { c with usepbo
= bool_of_string
v }
6437 | "wheel-scrolls-pages" -> { c with wheelbypage
= bool_of_string
v }
6438 | "horizontal-scrollbar-visible" ->
6441 then c.scrollb
lor scrollbhv
6442 else c.scrollb
land (lnot
scrollbhv)
6444 { c with scrollb
= b }
6445 | "vertical-scrollbar-visible" ->
6448 then c.scrollb
lor scrollbvv
6449 else c.scrollb
land (lnot
scrollbvv)
6451 { c with scrollb
= b }
6452 | "remote-in-a-new-instance" -> { c with riani
= bool_of_string
v }
6455 prerr_endline
("Error processing attribute (`" ^
6456 k ^
"'=`" ^
v ^
"'): " ^ exntos exn
);
6459 let rec fold c = function
6462 let c = apply c k v in
6465 fold { c with keyhashes
= copykeyhashes c } attrs
;
6468 let fromstring f pos
n v d =
6471 dolog
"Error processing attribute (%S=%S) at %d\n%s"
6472 n v pos
(exntos exn
)
6477 let bookmark_of attrs
=
6478 let rec fold title page
rely visy
= function
6479 | ("title", v) :: rest
-> fold v page
rely visy rest
6480 | ("page", v) :: rest
-> fold title v rely visy rest
6481 | ("rely", v) :: rest
-> fold title page
v visy rest
6482 | ("visy", v) :: rest
-> fold title page
rely v rest
6483 | _ :: rest
-> fold title page
rely visy rest
6484 | [] -> title, page
, rely, visy
6486 fold "invalid" "0" "0" "0" attrs
6490 let rec fold path page
rely pan visy
= function
6491 | ("path", v) :: rest
-> fold v page
rely pan visy rest
6492 | ("page", v) :: rest
-> fold path v rely pan visy rest
6493 | ("rely", v) :: rest
-> fold path page
v pan visy rest
6494 | ("pan", v) :: rest
-> fold path page
rely v visy rest
6495 | ("visy", v) :: rest
-> fold path page
rely pan
v rest
6496 | _ :: rest
-> fold path page
rely pan visy rest
6497 | [] -> path, page
, rely, pan
, visy
6499 fold "" "0" "0" "0" "0" attrs
6503 let rec fold rs ls
= function
6504 | ("out", v) :: rest
-> fold v ls rest
6505 | ("in", v) :: rest
-> fold rs
v rest
6506 | _ :: rest
-> fold ls rs rest
6512 let setconf dst
src =
6513 dst
.scrollbw
<- src.scrollbw
;
6514 dst
.scrollh
<- src.scrollh
;
6515 dst
.icase
<- src.icase
;
6516 dst
.preload <- src.preload;
6517 dst
.pagebias
<- src.pagebias
;
6518 dst
.verbose
<- src.verbose
;
6519 dst
.scrollstep
<- src.scrollstep
;
6520 dst
.maxhfit
<- src.maxhfit
;
6521 dst
.crophack
<- src.crophack
;
6522 dst
.autoscrollstep
<- src.autoscrollstep
;
6523 dst
.maxwait
<- src.maxwait
;
6524 dst
.hlinks
<- src.hlinks
;
6525 dst
.underinfo
<- src.underinfo
;
6526 dst
.interpagespace
<- src.interpagespace
;
6527 dst
.zoom <- src.zoom;
6528 dst
.presentation
<- src.presentation
;
6529 dst
.angle
<- src.angle
;
6530 dst
.cwinw
<- src.cwinw
;
6531 dst
.cwinh
<- src.cwinh
;
6532 dst
.savebmarks
<- src.savebmarks
;
6533 dst
.memlimit
<- src.memlimit
;
6534 dst
.fitmodel
<- src.fitmodel
;
6535 dst
.texcount
<- src.texcount
;
6536 dst
.sliceheight
<- src.sliceheight
;
6537 dst
.thumbw
<- src.thumbw
;
6538 dst
.jumpback
<- src.jumpback
;
6539 dst
.bgcolor
<- src.bgcolor
;
6540 dst
.tilew
<- src.tilew
;
6541 dst
.tileh
<- src.tileh
;
6542 dst
.mustoresize
<- src.mustoresize
;
6543 dst
.checkers
<- src.checkers
;
6544 dst
.aalevel
<- src.aalevel
;
6545 dst
.trimmargins
<- src.trimmargins
;
6546 dst
.trimfuzz
<- src.trimfuzz
;
6547 dst
.urilauncher
<- src.urilauncher
;
6548 dst
.colorspace
<- src.colorspace
;
6549 dst
.invert
<- src.invert
;
6550 dst
.colorscale
<- src.colorscale
;
6551 dst
.redirectstderr <- src.redirectstderr;
6552 dst
.ghyllscroll
<- src.ghyllscroll
;
6553 dst
.columns
<- src.columns
;
6554 dst
.beyecolumns
<- src.beyecolumns
;
6555 dst
.selcmd
<- src.selcmd
;
6556 dst
.updatecurs
<- src.updatecurs
;
6557 dst
.pathlauncher
<- src.pathlauncher
;
6558 dst
.keyhashes
<- copykeyhashes src;
6559 dst
.hfsize
<- src.hfsize
;
6560 dst
.hscrollstep
<- src.hscrollstep
;
6561 dst
.pgscale <- src.pgscale;
6562 dst
.usepbo
<- src.usepbo
;
6563 dst
.wheelbypage
<- src.wheelbypage
;
6564 dst
.stcmd
<- src.stcmd
;
6565 dst
.scrollb
<- src.scrollb
;
6566 dst
.riani
<- src.riani
;
6570 let h = Hashtbl.create
10 in
6571 let dc = { defconf with angle
= defconf.angle
} in
6572 let rec toplevel v t spos
_ =
6574 | Vdata
| Vcdata
| Vend
-> v
6575 | Vopen
("llppconfig", _, closed
) ->
6578 else { v with f = llppconfig
}
6580 error
"unexpected subelement at top level" s spos
6581 | Vclose
_ -> error
"unexpected close at top level" s spos
6583 and llppconfig
v t spos
_ =
6585 | Vdata
| Vcdata
-> v
6586 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6587 | Vopen
("defaults", attrs
, closed
) ->
6588 let c = config_of dc attrs
in
6592 else { v with f = defaults
}
6594 | Vopen
("ui-font", attrs
, closed
) ->
6595 let rec getsize size
= function
6597 | ("size", v) :: rest
->
6599 fromstring int_of_string spos
"size" v fstate.fontsize
in
6601 | l -> getsize size l
6603 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6606 else { v with f = uifont
(Buffer.create
10) }
6608 | Vopen
("doc", attrs
, closed
) ->
6609 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
6610 let path = unent pathent
6611 and pageno = fromstring int_of_string spos
"page" spage
0
6612 and rely = fromstring float_of_string spos
"rely" srely
0.0
6613 and pan
= fromstring int_of_string spos
"pan" span
0
6614 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6615 let c = config_of dc attrs
in
6616 let anchor = (pageno, rely, visy
) in
6618 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6619 else { v with f = doc
path pan
anchor c [] }
6622 error
"unexpected subelement in llppconfig" s spos
6624 | Vclose
"llppconfig" -> { v with f = toplevel }
6625 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6627 and defaults
v t spos
_ =
6629 | Vdata
| Vcdata
-> v
6630 | Vend
-> error
"unexpected end of input in defaults" s spos
6631 | Vopen
("keymap", attrs
, closed
) ->
6633 try List.assoc
"mode" attrs
6634 with Not_found
-> "global" in
6639 let h = findkeyhash dc modename in
6640 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6643 { v with f = pkeymap
ret KeyMap.empty }
6645 | Vopen
(_, _, _) ->
6646 error
"unexpected subelement in defaults" s spos
6648 | Vclose
"defaults" ->
6649 { v with f = llppconfig
}
6651 | Vclose
_ -> error
"unexpected close in defaults" s spos
6653 and uifont
b v t spos
epos =
6656 Buffer.add_substring
b s spos
(epos - spos
);
6658 | Vopen
(_, _, _) ->
6659 error
"unexpected subelement in ui-font" s spos
6660 | Vclose
"ui-font" ->
6661 if String.length
!fontpath = 0
6662 then fontpath := Buffer.contents
b;
6663 { v with f = llppconfig
}
6664 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6665 | Vend
-> error
"unexpected end of input in ui-font" s spos
6667 and doc
path pan
anchor c bookmarks
v t spos
_ =
6669 | Vdata
| Vcdata
-> v
6670 | Vend
-> error
"unexpected end of input in doc" s spos
6671 | Vopen
("bookmarks", _, closed
) ->
6674 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6676 | Vopen
("keymap", attrs
, closed
) ->
6678 try List.assoc
"mode" attrs
6679 with Not_found
-> "global"
6685 let h = findkeyhash c modename in
6686 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6687 doc
path pan
anchor c bookmarks
6689 { v with f = pkeymap
ret KeyMap.empty }
6691 | Vopen
(_, _, _) ->
6692 error
"unexpected subelement in doc" s spos
6695 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6696 { v with f = llppconfig
}
6698 | Vclose
_ -> error
"unexpected close in doc" s spos
6700 and pkeymap
ret keymap
v t spos
_ =
6702 | Vdata
| Vcdata
-> v
6703 | Vend
-> error
"unexpected end of input in keymap" s spos
6704 | Vopen
("map", attrs
, closed
) ->
6705 let r, l = map_of attrs
in
6706 let kss = fromstring keys_of_string spos
"in" r [] in
6707 let lss = fromstring keys_of_string spos
"out" l [] in
6711 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6712 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6715 then { v with f = pkeymap
ret keymap }
6718 { v with f = skip
"map" f }
6721 error
"unexpected subelement in keymap" s spos
6723 | Vclose
"keymap" ->
6724 { v with f = ret keymap }
6726 | Vclose
_ -> error
"unexpected close in keymap" s spos
6728 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6730 | Vdata
| Vcdata
-> v
6731 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6732 | Vopen
("item", attrs
, closed
) ->
6733 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
6734 let page = fromstring int_of_string spos
"page" spage
0
6735 and rely = fromstring float_of_string spos
"rely" srely
0.0
6736 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
6738 (unent titleent, 0, (page, rely, visy
)) :: bookmarks
6741 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6744 { v with f = skip
"item" f }
6747 error
"unexpected subelement in bookmarks" s spos
6749 | Vclose
"bookmarks" ->
6750 { v with f = doc
path pan
anchor c bookmarks }
6752 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6754 and skip tag
f v t spos
_ =
6756 | Vdata
| Vcdata
-> v
6758 error
("unexpected end of input in skipped " ^ tag
) s spos
6759 | Vopen
(tag'
, _, closed
) ->
6763 let f'
() = { v with f = skip tag
f } in
6764 { v with f = skip tag'
f'
}
6768 else error
("unexpected close in skipped " ^ tag
) s spos
6771 parse
{ f = toplevel; accu = () } s;
6777 let len = in_channel_length ic
in
6778 let s = String.create
len in
6779 really_input ic
s 0 len;
6782 | Parse_error
(msg
, s, pos
) ->
6783 let subs = subs s pos
in
6784 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6785 failwith
("parse error: " ^
s)
6788 failwith
("config load error: " ^ exntos exn
)
6794 let dir = Filename.concat
home ".config" in
6795 if Sys.is_directory
dir then dir else home
6798 Filename.concat
dir "llpp.conf"
6801 let confpath = ref defconfpath;;
6804 if Sys.file_exists
!confpath
6807 (try Some
(open_in_bin
!confpath)
6810 ("Error opening configuration file `" ^
!confpath ^
"': " ^
6821 ("Error loading configuration from `" ^
!confpath ^
"': " ^
6830 f (Hashtbl.create
0, defconf)
6835 let pc, pb
, px, pa
=
6838 if String.length
state.origin
= 0
6842 Hashtbl.find h (Filename.basename
key)
6843 with Not_found
-> dc, [], 0, emptyanchor
6847 state.bookmarks <- pb
;
6850 then state.anchor <- pa
;
6851 cbput state.hists
.nav pa
;
6857 let add_attrs bb always
dc c =
6860 then Printf.bprintf bb
"\n %s='%b'" s a
6863 then Printf.bprintf bb
"\n %s='%d'" s a
6866 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6869 then Printf.bprintf bb
"\n %s='%g'" s (a*.100.)
6872 then Printf.bprintf bb
"\n %s='%f'" s a
6876 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6880 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6884 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6888 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6894 | Some
(_N
, _A
, _B
) ->
6895 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6905 else string_of_float
f
6907 Printf.bprintf bb
"\n %s='%s'" s v
6912 | Cmulti
((n, a, b), _) when n > 1 ->
6913 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6914 | Csplit
(n, _) when n > 1 ->
6915 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6921 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6926 Printf.bprintf bb
"\n %s='%s'" s (fitmodel_to_string a)
6930 Printf.bprintf bb
"\n %s='%b'" s (a land m != 0)
6932 oi
"width" c.cwinw
dc.cwinw
;
6933 oi
"height" c.cwinh
dc.cwinh
;
6934 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6935 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6936 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
6937 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
6938 ob "case-insensitive-search" c.icase
dc.icase
;
6939 ob "preload" c.preload dc.preload;
6940 oi
"page-bias" c.pagebias
dc.pagebias
;
6941 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6942 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6943 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6944 ob "crop-hack" c.crophack
dc.crophack
;
6945 oW
"throttle" c.maxwait
dc.maxwait
;
6946 ob "highlight-links" c.hlinks
dc.hlinks
;
6947 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6948 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
6949 oz
"zoom" c.zoom dc.zoom;
6950 ob "presentation" c.presentation
dc.presentation
;
6951 oi
"rotation-angle" c.angle
dc.angle
;
6952 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6953 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
6954 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6955 oi
"tex-count" c.texcount
dc.texcount
;
6956 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6957 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6958 ob "persistent-location" c.jumpback
dc.jumpback
;
6959 oc
"background-color" c.bgcolor
dc.bgcolor
;
6960 oi
"tile-width" c.tilew
dc.tilew
;
6961 oi
"tile-height" c.tileh
dc.tileh
;
6962 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6963 ob "checkers" c.checkers
dc.checkers
;
6964 oi
"aalevel" c.aalevel
dc.aalevel
;
6965 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6966 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6967 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6968 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6969 oC
"color-space" c.colorspace
dc.colorspace
;
6970 ob "invert-colors" c.invert
dc.invert
;
6971 oF
"brightness" c.colorscale
dc.colorscale
;
6972 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6973 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6974 oco
"columns" c.columns
dc.columns
;
6975 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6976 os
"selection-command" c.selcmd
dc.selcmd
;
6977 os
"synctex-command" c.stcmd
dc.stcmd
;
6978 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6979 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6980 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
6981 oF
"page-scroll-scale" c.pgscale dc.pgscale;
6982 ob "use-pbo" c.usepbo
dc.usepbo
;
6983 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
6984 ob "remote-in-a-new-instance" c.riani
dc.riani
;
6987 let keymapsbuf always
dc c =
6988 let bb = Buffer.create
16 in
6989 let rec loop = function
6991 | (modename, h) :: rest
->
6992 let dh = findkeyhash dc modename in
6993 if always
|| h <> dh
6995 if Hashtbl.length
h > 0
6997 if Buffer.length
bb > 0
6998 then Buffer.add_char
bb '
\n'
;
6999 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
7000 Hashtbl.iter
(fun i
o ->
7001 let isdifferent = always
||
7003 let dO = Hashtbl.find dh i
in
7005 with Not_found
-> true
7010 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
7011 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
7012 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
7013 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
7014 Buffer.add_string
bb (Wsi.keyname
k);
7017 let rec loop = function
7019 | km
:: [] -> addkm km
7020 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
7024 Buffer.add_string
bb "<map in='";
7028 Buffer.add_string
bb "' out='";
7030 Buffer.add_string
bb "'/>\n"
7033 Buffer.add_string
bb "' out='";
7035 Buffer.add_string
bb "'/>\n"
7037 | KMmulti
(ins, kms
) ->
7038 Buffer.add_char
bb ' '
;
7040 Buffer.add_string
bb "' out='";
7042 Buffer.add_string
bb "'/>\n"
7044 Buffer.add_string
bb "</keymap>";
7054 let uifontsize = fstate.fontsize
in
7055 let bb = Buffer.create
32768 in
7056 let relx = float state.x /. float state.winw in
7058 let cx w = truncate
(relx *. float w) in
7060 (fun (w, h, x) ws
->
7062 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
7063 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
7064 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
7066 (state.winw, state.winh
, state.x) state.winstate
7071 let dc = if conf.bedefault
then conf else dc in
7072 Buffer.add_string
bb "<llppconfig>\n";
7074 if String.length
!fontpath > 0
7076 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
7082 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
7085 Buffer.add_string
bb "<defaults ";
7086 add_attrs bb true dc dc;
7087 let kb = keymapsbuf true dc dc in
7088 if Buffer.length
kb > 0
7090 Buffer.add_string
bb ">\n";
7091 Buffer.add_buffer
bb kb;
7092 Buffer.add_string
bb "\n</defaults>\n";
7094 else Buffer.add_string
bb "/>\n";
7096 let adddoc path pan
anchor c bookmarks =
7097 if bookmarks == [] && c = dc && anchor = emptyanchor
7100 Printf.bprintf
bb "<doc path='%s'"
7101 (enent
path 0 (String.length
path));
7103 if anchor <> emptyanchor
7105 let n, rely, visy
= anchor in
7106 Printf.bprintf
bb " page='%d'" n;
7109 Printf.bprintf
bb " rely='%f'" rely
7111 if abs_float visy
> 1e-6
7113 Printf.bprintf
bb " visy='%f'" visy
7118 then Printf.bprintf
bb " pan='%d'" pan
;
7120 add_attrs bb false dc c;
7121 let kb = keymapsbuf false dc c in
7123 begin match bookmarks with
7125 if Buffer.length
kb > 0
7127 Buffer.add_string
bb ">\n";
7128 Buffer.add_buffer
bb kb;
7129 Buffer.add_string
bb "\n</doc>\n";
7131 else Buffer.add_string
bb "/>\n"
7133 Buffer.add_string
bb ">\n<bookmarks>\n";
7134 List.iter
(fun (title, _level
, (page, rely, visy
)) ->
7136 "<item title='%s' page='%d'"
7137 (enent
title 0 (String.length
title))
7142 Printf.bprintf
bb " rely='%f'" rely
7144 if abs_float visy
> 1e-6
7146 Printf.bprintf
bb " visy='%f'" visy
7148 Buffer.add_string
bb "/>\n";
7150 Buffer.add_string
bb "</bookmarks>";
7151 if Buffer.length
kb > 0
7153 Buffer.add_string
bb "\n";
7154 Buffer.add_buffer
bb kb;
7156 Buffer.add_string
bb "\n</doc>\n";
7162 match state.mode with
7163 | Birdseye
(c, pan, _, _, _) ->
7165 match conf.columns
with
7166 | Cmulti
((c, _, _), _) -> Some
c
7170 match c.columns
with
7171 | Cmulti
(c, _) -> Cmulti
(c, [||])
7172 | Csingle
_ -> Csingle
[||]
7173 | Csplit
_ -> failwith
"quit from bird's eye while split"
7175 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
7178 let basename = Filename.basename
7179 (if String.length
state.origin
= 0 then state.path else state.origin
)
7181 adddoc basename pan (getanchor ())
7183 let autoscrollstep =
7184 match state.autoscroll
with
7186 | None
-> conf.autoscrollstep
7188 match state.mode with
7189 | Birdseye
(bc
, _, _, _, _) ->
7192 presentation
= bc
.presentation
;
7193 interpagespace
= bc
.interpagespace
;
7194 maxwait
= bc
.maxwait
;
7195 autoscrollstep = autoscrollstep }
7196 | _ -> { conf with autoscrollstep = autoscrollstep }
7198 (if conf.savebmarks
then state.bookmarks else []);
7200 Hashtbl.iter
(fun path (c, bookmarks, x, anchor) ->
7202 then adddoc path x anchor c bookmarks
7204 Buffer.add_string
bb "</llppconfig>\n";
7207 if load1 f && Buffer.length
bb > 0
7210 let tmp = !confpath ^
".tmp" in
7211 let oc = open_out_bin
tmp in
7212 Buffer.output_buffer
oc bb;
7214 Unix.rename
tmp !confpath;
7217 ("error while saving configuration: " ^ exntos exn
)
7221 let adderrmsg src msg
=
7222 Buffer.add_string
state.errmsgs msg
;
7223 state.newerrmsgs
<- true;
7227 let adderrfmt src fmt
=
7228 Format.kprintf
(fun s -> adderrmsg src s) fmt
;
7232 let cl = splitatspace cmds
in
7234 try Scanf.sscanf
s fmt
f
7236 adderrfmt "remote exec"
7237 "error processing '%S': %s\n" cmds
(exntos exn
)
7240 | "reload" :: [] -> reload ()
7241 | "goto" :: args :: [] ->
7242 scan args "%u %f %f"
7244 let cmd, _ = state.geomcmds
in
7245 if String.length
cmd = 0
7246 then gotopagexy pageno x y
7249 gotopagexy pageno x y;
7252 state.reprf
<- f state.reprf
7254 | "goto1" :: args :: [] -> scan args "%u %f" gotopage
7255 | "rect" :: args :: [] ->
7256 scan args "%u %u %f %f %f %f"
7257 (fun pageno color x0 y0 x1 y1 ->
7258 onpagerect pageno (fun w h ->
7259 let _,w1,h1
,_ = getpagedim pageno in
7260 let sw = float w1 /. w
7261 and sh = float h1
/. h in
7265 and y1s
= y1 *. sh in
7266 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
7268 state.rects <- (pageno, color, rect) :: state.rects;
7269 G.postRedisplay "rect";
7272 | "activatewin" :: [] -> Wsi.activatewin
()
7273 | "quit" :: [] -> raise Quit
7275 adderrfmt "remote command"
7276 "error processing remote command: %S\n" cmds
;
7280 let scratch = String.create
80 in
7281 let buf = Buffer.create
80 in
7284 try Some
(Unix.read fd
scratch 0 80)
7286 | Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
7287 | Unix.Unix_error
(Unix.EINTR
, _, _) -> tempfr ()
7290 match tempfr () with
7296 if Buffer.length
buf > 0
7298 let s = Buffer.contents
buf in
7308 let pos = String.index_from
scratch ppos '
\n'
in
7309 if pos >= n then -1 else pos
7310 with Not_found
-> -1
7314 Buffer.add_substring
buf scratch ppos
(nlpos-ppos
);
7315 let s = Buffer.contents
buf in
7321 Buffer.add_substring
buf scratch ppos
(n-ppos
);
7327 let remoteopen path =
7328 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0
)
7330 adderrfmt "remoteopen" "error opening %S: %s" path (exntos exn
);
7335 let trimcachepath = ref "" in
7336 let rcmdpath = ref "" in
7337 selfexec := Sys.executable_name
;
7340 [("-p", Arg.String
(fun s -> state.password
<- s),
7341 "<password> Set password");
7345 Config.fontpath := s;
7346 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
7348 "<path> Set path to the user interface font");
7352 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
7353 Config.confpath := s),
7354 "<path> Set path to the configuration file");
7356 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
7357 "<path> Set path to the trim cache file");
7359 ("-dest", Arg.String
(fun s -> state.nameddest
<- s),
7360 "<named-destination> Set named destination");
7362 ("-wtmode", Arg.Set
wtmode, " Operate in wt mode");
7364 ("-remote", Arg.String
(fun s -> rcmdpath := s),
7365 "<path> Set path to the remote commands source");
7367 ("-origin", Arg.String
(fun s -> state.origin
<- s),
7368 "<original-path> Set original path");
7370 ("-v", Arg.Unit
(fun () ->
7372 "%s\nconfiguration path: %s\n"
7376 exit
0), " Print version and exit");
7379 (fun s -> state.path <- s)
7380 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
7383 then selfexec := !selfexec ^
" -wtmode";
7385 if String.length
state.path = 0
7386 then (prerr_endline
"file name missing"; exit
1);
7388 if not
(Config.load ())
7389 then prerr_endline
"failed to load configuration";
7391 let wsfd, winw, winh
= Wsi.init
(object
7392 val mutable m_hack
= false
7393 method expose
= if not m_hack
then G.postRedisplay "expose"
7394 method visible
= G.postRedisplay "visible"
7395 method display = m_hack
<- false; display ()
7396 method reshape w h =
7397 m_hack
<- w < state.winw && h < state.winh
;
7399 method mouse b d x y m = mouse b d x y m
7400 method motion x y = state.mpos
<- (x, y); motion x y
7401 method pmotion x y = state.mpos
<- (x, y); pmotion x y
7403 let mascm = m land (
7404 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
7406 match state.keystate
with
7408 let km = k, mascm in
7411 let modehash = state.uioh#
modehash in
7412 try Hashtbl.find modehash km
7414 try Hashtbl.find (findkeyhash conf "global") km
7415 with Not_found
-> KMinsrt
(k, m)
7417 | KMinsrt
(k, m) -> keyboard k m
7418 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
7419 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
7421 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
7422 List.iter
(fun (k, m) -> keyboard k m) insrt
;
7423 state.keystate
<- KSnone
7424 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
7425 state.keystate
<- KSinto
(keys
, insrt
)
7427 state.keystate
<- KSnone
7429 method enter
x y = state.mpos
<- (x, y); pmotion x y
7430 method leave = state.mpos
<- (-1, -1)
7431 method winstate wsl
= state.winstate
<- wsl
7432 method quit
= raise Quit
7433 end) conf.cwinw
conf.cwinh
(platform = Posx
) in
7438 List.exists
GlMisc.check_extension
7439 [ "GL_ARB_texture_rectangle"
7440 ; "GL_EXT_texture_recangle"
7441 ; "GL_NV_texture_rectangle" ]
7443 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
7446 let r = GlMisc.get_string `renderer
in
7447 let p = "Mesa DRI Intel(" in
7448 let l = String.length
p in
7449 String.length
r > l && String.sub
r 0 l = p
7451 then defconf.sliceheight
<- 1024;
7454 match Ne.pipe () with
7456 Printf.eprintf
"pipe/crsw failed: %s" (exntos exn
);
7460 match Ne.pipe () with
7462 Printf.eprintf
"pipe/srcw failed: %s" (exntos exn
);
7472 setcheckers conf.checkers
;
7476 conf.angle
, conf.fitmodel
, (conf.trimmargins
, conf.trimfuzz
),
7477 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
7478 !Config.fontpath, !trimcachepath,
7479 GlMisc.check_extension
"GL_ARB_pixel_buffer_object"
7483 state.text <- "Opening " ^
(mbtoutf8
state.path);
7485 opendoc state.path state.password
;
7489 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
7492 if String.length
!rcmdpath > 0
7493 then remoteopen !rcmdpath
7498 let rec loop deadline
=
7500 match state.errfd
with
7501 | None
-> [state.sr
; state.wsfd]
7502 | Some fd
-> [state.sr
; state.wsfd; fd
]
7507 | Some fd
-> fd
:: r
7511 state.redisplay
<- false;
7518 if deadline
= infinity
7520 else max
0.0 (deadline
-. now)
7525 try Unix.select
r [] [] timeout
7526 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
7532 if state.ghyll
== noghyll
7534 match state.autoscroll
with
7535 | Some step
when step
!= 0 ->
7536 let y = state.y + step
in
7540 else if y >= state.maxy then 0 else y
7543 if state.mode = View
7544 then state.text <- "";
7547 else deadline
+. 0.01
7552 let rec checkfds = function
7554 | fd
:: rest
when fd
= state.sr
->
7555 let cmd = readcmd state.sr
in
7559 | fd
:: rest
when fd
= state.wsfd ->
7563 | fd
:: rest
when Some fd
= !optrfd ->
7564 begin match remote fd
with
7565 | None
-> optrfd := remoteopen !rcmdpath;
7566 | opt -> optrfd := opt
7571 let s = String.create
80 in
7572 let n = tempfailureretry
(Unix.read fd
s 0) 80 in
7573 if conf.redirectstderr
7575 Buffer.add_substring
state.errmsgs
s 0 n;
7576 state.newerrmsgs
<- true;
7577 state.redisplay
<- true;
7580 prerr_string
(String.sub
s 0 n);
7588 if deadline
= infinity
7592 match state.autoscroll
with
7593 | Some step
when step
!= 0 -> deadline1
7594 | _ -> if state.ghyll
== noghyll then infinity
else deadline1