6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and irect
= (int * int * int * int)
39 and trimparams
= (trimmargins
* irect
)
40 and colorspace
= | Rgb
| Bgr
| Gray
49 | LDfirstvisible
of (int * int * int)
64 | KMmulti
of key list
* key list
66 and keyhash
= (key
, keymap
) Hashtbl.t
69 | KSinto
of (key list
* key list
)
72 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
73 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
75 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
77 external init
: pipe
-> params
-> unit = "ml_init";;
78 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
79 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
80 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
81 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
82 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
83 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
84 external measurestr
: int -> string -> float = "ml_measure_string";;
85 external getmaxw
: unit -> float = "ml_getmaxw";;
86 external postprocess
: opaque
-> int -> int -> int -> int -> int =
88 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
89 external platform
: unit -> platform
= "ml_platform";;
90 external setaalevel
: int -> unit = "ml_setaalevel";;
91 external realloctexts
: int -> bool = "ml_realloctexts";;
92 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
93 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
94 external getlink
: opaque
-> int -> under
= "ml_getlink";;
95 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
96 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
97 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
98 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
100 let platform_to_string = function
101 | Punknown
-> "unknown"
105 | Pfreebsd
-> "FreeBSD"
106 | Pdragonflybsd
-> "DragonflyBSD"
107 | Popenbsd
-> "OpenBSD"
108 | Pnetbsd
-> "NetBSD"
109 | Pcygwin
-> "Cygwin"
112 let platform = platform ();;
118 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
121 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
123 type mpos
= int * int
125 | Msel
of (mpos
* mpos
)
127 | Mscrolly
| Mscrollx
128 | Mzoom
of (int * int)
129 | Mzoomrect
of (mpos
* mpos
)
133 type textentry
= string * string * onhist
option * onkey
* ondone
134 and onkey
= string -> int -> te
135 and ondone
= string -> unit
136 and histcancel
= unit -> unit
137 and onhist
= ((histcmd
-> string) * histcancel
)
138 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
143 | TEswitch
of textentry
154 let bound v minv maxv
=
155 max minv
(min maxv v
);
159 { store
= Array.create n v
166 let drawstring size x y s
=
168 Gl.enable `texture_2d
;
169 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
170 ignore
(drawstr size x y s
);
172 Gl.disable `texture_2d
;
175 let drawstring1 size x y s
=
179 let drawstring2 size x y fmt
=
180 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
183 let cbcap b
= Array.length b
.store
;;
188 b
.wc
<- (b
.wc
+ 1) mod cap;
190 b
.len
<- min
(b
.len
+ 1) cap;
193 let cbempty b
= b
.len
= 0;;
195 let cbgetg b circular dir
=
199 let rc = b
.rc + dir
in
211 else max
0 (min
rc (b
.len
-1))
217 let cbget b
= cbgetg b
false;;
218 let cbgetc b
= cbgetg b
true;;
235 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
236 dolog " WxH %dx%d" l
.pagew l
.pageh
;
237 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
238 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
239 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
243 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
245 dolog " x0,y0=(% f, % f)" x0 y0
;
246 dolog " x1,y1=(% f, % f)" x1 y1
;
247 dolog " x2,y2=(% f, % f)" x2 y2
;
248 dolog " x3,y3=(% f, % f)" x3 y3
;
252 type multicolumns
= multicol
* pagegeom
253 and splitcolumns
= columncount
* pagegeom
254 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
255 and multicol
= columncount
* covercount
* covercount
257 and columncount
= int
258 and covercount
= int;;
261 { mutable scrollbw
: int
262 ; mutable scrollh
: int
263 ; mutable icase
: bool
264 ; mutable preload
: bool
265 ; mutable pagebias
: int
266 ; mutable verbose
: bool
267 ; mutable debug
: bool
268 ; mutable scrollstep
: int
269 ; mutable maxhfit
: bool
270 ; mutable crophack
: bool
271 ; mutable autoscrollstep
: int
272 ; mutable maxwait
: float option
273 ; mutable hlinks
: bool
274 ; mutable underinfo
: bool
275 ; mutable interpagespace
: interpagespace
276 ; mutable zoom
: float
277 ; mutable presentation
: bool
278 ; mutable angle
: angle
281 ; mutable savebmarks
: bool
282 ; mutable proportional
: proportional
283 ; mutable trimmargins
: trimmargins
284 ; mutable trimfuzz
: irect
285 ; mutable memlimit
: memsize
286 ; mutable texcount
: texcount
287 ; mutable sliceheight
: sliceheight
288 ; mutable thumbw
: width
289 ; mutable jumpback
: bool
290 ; mutable bgcolor
: float * float * float
291 ; mutable bedefault
: bool
292 ; mutable scrollbarinpm
: bool
293 ; mutable tilew
: int
294 ; mutable tileh
: int
295 ; mutable mustoresize
: memsize
296 ; mutable checkers
: bool
297 ; mutable aalevel
: int
298 ; mutable urilauncher
: string
299 ; mutable pathlauncher
: string
300 ; mutable colorspace
: colorspace
301 ; mutable invert
: bool
302 ; mutable colorscale
: float
303 ; mutable redirectstderr
: bool
304 ; mutable ghyllscroll
: (int * int * int) option
305 ; mutable columns
: columns
306 ; mutable beyecolumns
: columncount
option
307 ; mutable selcmd
: string
308 ; mutable updatecurs
: bool
309 ; mutable keyhashes
: (string * keyhash
) list
313 | Cmulti
of multicolumns
314 | Csplit
of splitcolumns
317 type anchor
= pageno
* top
;;
319 type outline
= string * int * anchor
;;
321 type rect
= float * float * float * float * float * float * float * float;;
323 type tile
= opaque
* pixmapsize
* elapsed
324 and elapsed
= float;;
325 type pagemapkey
= pageno
* gen
;;
326 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
330 let emptyanchor = (0, 0.0);;
332 type infochange
= | Memused
| Docinfo
| Pdim
;;
334 class type uioh
= object
335 method display
: unit
336 method key
: int -> int -> uioh
337 method button
: int -> bool -> int -> int -> int -> uioh
338 method motion
: int -> int -> uioh
339 method pmotion
: int -> int -> uioh
340 method infochanged
: infochange
-> unit
341 method scrollpw
: (int * float * float)
342 method scrollph
: (int * float * float)
343 method modehash
: keyhash
347 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
348 | Textentry
of (textentry
* onleave
)
350 | LinkNav
of linktarget
351 and onleave
= leavetextentrystatus
-> unit
352 and leavetextentrystatus
= | Cancel
| Confirm
353 and helpitem
= string * int * action
356 | Action
of (uioh
-> uioh
)
358 | Ltexact
of (pageno
* int)
362 let isbirdseye = function Birdseye _
-> true | _
-> false;;
363 let istextentry = function Textentry _
-> true | _
-> false;;
367 | Loading
of (page
* gen
)
369 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
371 | Outlining
of outline list
374 let emptykeyhash = Hashtbl.create
0;;
375 let nouioh : uioh
= object (self
)
377 method key _ _
= self
378 method button _ _ _ _ _
= self
379 method motion _ _
= self
380 method pmotion _ _
= self
381 method infochanged _
= ()
382 method scrollpw
= (0, nan
, nan
)
383 method scrollph
= (0, nan
, nan
)
384 method modehash
= emptykeyhash
388 { mutable sr
: Unix.file_descr
389 ; mutable sw
: Unix.file_descr
390 ; mutable wsfd
: Unix.file_descr
391 ; mutable errfd
: Unix.file_descr
option
392 ; mutable stderr
: Unix.file_descr
393 ; mutable errmsgs
: Buffer.t
394 ; mutable newerrmsgs
: bool
398 ; mutable scrollw
: int
399 ; mutable hscrollh
: int
400 ; mutable anchor
: anchor
401 ; mutable ranchors
: (string * string * anchor
) list
403 ; mutable layout
: page list
404 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
405 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
406 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
407 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
408 ; mutable pagecount
: int
409 ; mutable currently
: currently
410 ; mutable mstate
: mstate
411 ; mutable searchpattern
: string
412 ; mutable rects
: (pageno
* recttype
* rect
) list
413 ; mutable rects1
: (pageno
* recttype
* rect
) list
414 ; mutable text
: string
415 ; mutable fullscreen
: (width
* height
) option
416 ; mutable mode
: mode
417 ; mutable uioh
: uioh
418 ; mutable outlines
: outline array
419 ; mutable bookmarks
: outline list
420 ; mutable path
: string
421 ; mutable password
: string
422 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
423 ; mutable memused
: memsize
425 ; mutable throttle
: (page list
* int * float) option
426 ; mutable autoscroll
: int option
427 ; mutable ghyll
: (int option -> unit)
428 ; mutable help
: helpitem array
429 ; mutable docinfo
: (int * string) list
430 ; mutable texid
: GlTex.texture_id
option
432 ; mutable prevzoom
: float
433 ; mutable progress
: float
434 ; mutable redisplay
: bool
435 ; mutable mpos
: mpos
436 ; mutable keystate
: keystate
437 ; mutable glinks
: bool
440 { pat
: string circbuf
441 ; pag
: string circbuf
442 ; nav
: anchor circbuf
443 ; sel
: string circbuf
464 ; presentation
= false
469 ; proportional
= true
470 ; trimmargins
= false
471 ; trimfuzz
= (0,0,0,0)
472 ; memlimit
= 32 lsl 20
477 ; bgcolor
= (0.5, 0.5, 0.5)
479 ; scrollbarinpm
= true
482 ; mustoresize
= 256 lsl 20
487 | Plinux
| Pfreebsd
| Pdragonflybsd
488 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
489 | Posx
-> "open \"%s\""
490 | Pcygwin
-> "cygstart \"%s\""
491 | Punknown
-> "echo %s")
492 ; pathlauncher
= "lp \"%s\""
495 | Plinux
| Pfreebsd
| Pdragonflybsd
496 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
503 ; redirectstderr
= false
509 let mk n
= (n
, Hashtbl.create
1) in
522 let findkeyhash c name
=
523 try List.assoc name c
.keyhashes
524 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
527 let conf = { defconf with angle
= defconf.angle
};;
530 { mutable fontsize
: int
531 ; mutable wwidth
: float
532 ; mutable maxrows
: int
544 fstate.fontsize
<- n
;
545 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
546 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
550 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
551 let len = String.length s
in
552 if colonpos >= 0 && colonpos + 3 < len
554 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
557 try String.rindex_from s
colonpos ' '
561 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
564 | "http" | "ftp" | "mailto" ->
566 try String.index_from s
colonpos ' '
567 with Not_found
-> len
569 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
577 if String.length
conf.urilauncher
= 0
578 then print_endline uri
580 let url = geturl uri
in
581 if String.length
url = 0
582 then print_endline uri
584 let re = Str.regexp
"%s" in
585 let command = Str.global_replace
re url conf.urilauncher
in
589 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
595 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
596 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
600 let strings = version () :: "" :: Help.keys
in
603 let url = geturl s
in
604 if String.length
url > 0
605 then (s
, 0, Action
(fun u
-> gotouri url; u
))
606 else (s
, 0, Noaction
)
611 let firstgeomcmds = "", [];;
618 ; stderr
= Unix.stderr
619 ; errmsgs
= Buffer.create
0
626 ; anchor
= emptyanchor
630 ; tilelru
= Queue.create
()
631 ; pagemap
= Hashtbl.create
10
632 ; tilemap
= Hashtbl.create
10
647 ; geomcmds
= firstgeomcmds
649 { nav
= cbnew 10 (0, 0.0)
675 Printf.kprintf prerr_endline fmt
677 Printf.kprintf ignore fmt
681 if String.length
conf.pathlauncher
= 0
682 then print_endline
state.path
684 let re = Str.regexp
"%s" in
685 let command = Str.global_replace
re state.path
conf.pathlauncher
in
689 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
694 let redirectstderr () =
695 if conf.redirectstderr
697 let rfd, wfd
= Unix.pipe
() in
698 state.stderr
<- Unix.dup
Unix.stderr
;
699 state.errfd
<- Some
rfd;
700 Unix.dup2 wfd
Unix.stderr
;
702 state.newerrmsgs
<- false;
703 begin match state.errfd
with
706 Unix.dup2
state.stderr
Unix.stderr
;
710 prerr_string
(Buffer.contents
state.errmsgs
);
712 Buffer.clear
state.errmsgs
;
718 let postRedisplay who
=
720 then prerr_endline
("redisplay for " ^ who
);
721 state.redisplay
<- true;
725 let getopaque pageno
=
726 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
727 with Not_found
-> None
730 let putopaque pageno opaque
=
731 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
734 let pagetranslatepoint l x y
=
735 let dy = y
- l
.pagedispy
in
736 let y = dy + l
.pagey
in
737 let dx = x
- l
.pagedispx
in
738 let x = dx + l
.pagex
in
745 begin match getopaque l
.pageno
with
747 let x0 = l
.pagedispx
in
748 let x1 = x0 + l
.pagevw
in
749 let y0 = l
.pagedispy
in
750 let y1 = y0 + l
.pagevh
in
751 if y >= y0 && y <= y1 && x >= x0 && x <= x1
753 let px, py
= pagetranslatepoint l
x y in
754 match whatsunder opaque
px py
with
767 state.text
<- Printf.sprintf
"%c%s" c s
;
768 G.postRedisplay "showtext";
771 let updateunder x y =
772 match getunder x y with
773 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
775 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
776 Wsi.setcursor
Wsi.CURSOR_INFO
777 | Ulinkgoto
(page
, _
) ->
779 then showtext 'p'
("age: " ^ string_of_int
(page
+1));
780 Wsi.setcursor
Wsi.CURSOR_INFO
782 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
783 Wsi.setcursor
Wsi.CURSOR_TEXT
785 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
786 Wsi.setcursor
Wsi.CURSOR_INHERIT
788 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
789 Wsi.setcursor
Wsi.CURSOR_INHERIT
791 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
792 Wsi.setcursor
Wsi.CURSOR_INHERIT
793 | Uremote
(filename
, pageno
) ->
794 if conf.underinfo
then showtext 'r'
795 (Printf.sprintf
"emote: %s (%d)" filename pageno
);
796 Wsi.setcursor
Wsi.CURSOR_INFO
799 let showlinktype under
=
805 showtext 'u'
("ri: " ^ uri
)
806 | Ulinkgoto
(page
, _
) ->
807 showtext 'p'
("age: " ^ string_of_int
(page
+1));
809 showtext '
f'
("ont: " ^ s
);
811 showtext 'u'
("nexpected: " ^ s
);
813 showtext 'l'
("aunch: " ^ s
);
815 showtext 'n'
("amed: " ^ s
);
816 | Uremote
(filename
, pageno
) ->
817 showtext 'r'
(Printf.sprintf
"emote: %s (%d)" filename pageno
);
821 let b = Buffer.create
(String.length s
+ 1) in
822 Buffer.add_string
b s
;
827 let colorspace_of_string s
=
828 match String.lowercase s
with
832 | _
-> failwith
"invalid colorspace"
835 let int_of_colorspace = function
841 let colorspace_of_int = function
845 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
848 let colorspace_to_string = function
854 let intentry_with_suffix text key
=
856 if key
>= 32 && key
< 127
860 match Char.lowercase
c with
862 let text = addchar text c in
866 let text = addchar text c in
870 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
874 let multicolumns_to_string (n
, a
, b) =
876 then Printf.sprintf
"%d" n
877 else Printf.sprintf
"%d,%d,%d" n a
b;
880 let multicolumns_of_string s
=
882 (int_of_string s
, 0, 0)
884 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
889 let n = Unix.read fd
s 0 4 in
890 if n != 4 then failwith
"incomplete read(len)";
892 lor (Char.code
s.[0] lsl 24)
893 lor (Char.code
s.[1] lsl 16)
894 lor (Char.code
s.[2] lsl 8)
895 lor (Char.code
s.[3] lsl 0)
897 let s = String.create
len in
898 let n = Unix.read fd
s 0 len in
899 if n != len then failwith
"incomplete read(data)";
903 let btod b = if b then 1 else 0;;
906 let b = Buffer.create
16 in
907 Buffer.add_string
b "llll";
910 let s = Buffer.contents
b in
911 let n = String.length
s in
913 (* dolog "wcmd %S" (String.sub s 4 len); *)
914 s.[0] <- Char.chr
((len lsr 24) land 0xff);
915 s.[1] <- Char.chr
((len lsr 16) land 0xff);
916 s.[2] <- Char.chr
((len lsr 8) land 0xff);
917 s.[3] <- Char.chr
(len land 0xff);
918 let n'
= Unix.write
state.sw
s 0 n in
919 if n'
!= n then failwith
"write failed";
926 let d = conf.winh
- h
in
933 let rec f pn ph pi fh l
=
935 | (n, _
, h
, _
) :: rest
->
936 let ips = calcips h
in
941 if isbirdseye state.mode
&& pn
= 0
946 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
951 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
955 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
958 let fh = f 0 0 0 0 state.pdims
in
963 match conf.columns
with
964 | Csingle
-> calcheight ()
966 if Array.length
b > 0
968 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
972 if Array.length
b > 0
974 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
979 let getpageyh pageno
=
980 let rec f pn ph pi
y l
=
982 | (n, _
, h
, _
) :: rest
->
983 let ips = calcips h
in
986 let h = if n = pageno
then h else ph
in
987 if conf.presentation
&& n = pageno
989 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
991 y + (pageno
- pn
) * (ph
+ pi
), h
993 let y = y + (if conf.presentation
then pi
else 0) in
994 let y = y + (n - pn
) * (ph
+ pi
) in
998 y + (pageno
- pn
) * (ph
+ pi
), ph
1000 f 0 0 0 0 state.pdims
1003 let getpageyh pageno
=
1004 match conf.columns
with
1005 | Csingle
-> getpageyh pageno
1007 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1011 let (_
, _
, y, (_
, _
, h, _
)) = b.(n) in
1015 let getpagedim pageno
=
1018 | (n, _
, _
, _
) as pdim
:: rest
->
1020 then (if n = pageno
then pdim
else ppdim
)
1025 f (-1, -1, -1, -1) state.pdims
1028 let getpagey pageno
= fst
(getpageyh pageno
);;
1030 let nogeomcmds cmds
=
1032 | s, [] -> String.length
s = 0
1037 let sh = sh - state.hscrollh
in
1038 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1039 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1041 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1042 let ips = calcips h in
1044 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1048 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1050 prev
, pdims
, pdimno
, 0
1052 let dy = dy + yinc in
1053 let py = py + yinc in
1054 if pageno
= state.pagecount
|| dy >= sh
1059 if py + h <= vy - yinc
1061 let py = py + h + ips in
1062 let dy = max
0 (py - y) in
1063 f ~pageno
:(pageno
+1)
1071 let pagey = vy - py in
1072 let pagevh = h - pagey in
1073 let pagevh = min
(sh - dy) pagevh in
1074 let off = if yinc > 0 then py - vy else 0 in
1075 let py = py + h + ips in
1078 if state.w
< conf.winw
- state.scrollw
1079 then (conf.winw
- state.scrollw
- state.w
) / 2
1082 let dispx = xoff + state.x in
1088 let lw = w
- pagex in
1089 min
lw (conf.winw
- state.scrollw
)
1093 ; pagedimno
= pdimno
1097 ; pagey = pagey + off
1099 ; pagevh = pagevh - off
1101 ; pagedispy
= dy + off
1104 let accu = e :: accu in
1105 f ~pageno
:(pageno
+1)
1126 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1127 let sh = sh - state.hscrollh
in
1128 let rec fold accu n =
1129 if n = Array.length
b
1132 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1135 || n = state.pagecount
- coverB
1136 || (n - coverA
) mod columns
= columns
- 1)
1142 let pagey = max
0 (y - vy) in
1143 let pagedispy = if pagey > 0 then 0 else vy - y in
1144 let pagedispx, pagex =
1146 if n = coverA
- 1 || n = state.pagecount
- coverB
1147 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1148 else dx + xoff + state.x
1155 let vw = conf.winw
- state.scrollw
- pagedispx in
1156 let pw = w
- pagex in
1159 let pagevh = min
(h - pagey) (sh - pagedispy) in
1160 if pagevw > 0 && pagevh > 0
1164 ; pagedimno
= pdimno
1171 ; pagedispx = pagedispx
1172 ; pagedispy = pagedispy
1183 List.rev
(fold [] 0)
1186 let layoutS (columns
, b) y sh =
1187 let sh = sh - state.hscrollh
in
1188 let rec fold accu n =
1189 if n = Array.length
b
1192 let pdimno, px, vy, (_
, pagew
, pageh
, xoff) = b.(n) in
1199 let x = xoff + state.x in
1200 let pagey = max
0 (y - vy) in
1201 let pagedispy = if pagey > 0 then 0 else vy - y in
1202 let pagedispx, pagex =
1217 let vw = conf.winw
- pagedispx - state.scrollw
in
1218 let pw = pagew
- pagex in
1221 let pagevw = min
pagevw (pagew
/columns
) in
1222 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1223 if pagevw > 0 && pagevh > 0
1226 { pageno
= n/columns
1227 ; pagedimno
= pdimno
1234 ; pagedispx = pagedispx
1235 ; pagedispy = pagedispy
1246 List.rev
(fold [] 0)
1250 if nogeomcmds state.geomcmds
1252 match conf.columns
with
1253 | Csingle
-> layout1 y sh
1254 | Cmulti
c -> layoutN c y sh
1255 | Csplit
s -> layoutS s y sh
1260 let y = state.y + incr
in
1262 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1267 let tilex = l
.pagex mod conf.tilew
in
1268 let tiley = l
.pagey mod conf.tileh
in
1270 let col = l
.pagex / conf.tilew
in
1271 let row = l
.pagey / conf.tileh
in
1273 let rec rowloop row y0 dispy
h =
1277 let dh = conf.tileh
- y0 in
1278 let dh = min
h dh in
1279 let rec colloop col x0 dispx w
=
1283 let dw = conf.tilew
- x0 in
1284 let dw = min w
dw in
1286 f col row dispx dispy
x0 y0 dw dh;
1287 colloop (col+1) 0 (dispx+dw) (w
-dw)
1290 colloop col tilex l
.pagedispx l
.pagevw;
1291 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1294 if l
.pagevw > 0 && l
.pagevh > 0
1295 then rowloop row tiley l
.pagedispy l
.pagevh;
1298 let gettileopaque l
col row =
1300 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1302 try Some
(Hashtbl.find
state.tilemap
key)
1303 with Not_found
-> None
1306 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1307 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1308 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1311 let drawtiles l color
=
1313 let f col row x y tilex tiley w
h =
1314 match gettileopaque l
col row with
1315 | Some
(opaque
, _
, t
) ->
1316 let params = x, y, w
, h, tilex, tiley in
1320 GlFunc.blend_func `zero `one_minus_src_color
;
1322 drawtile
params opaque
;
1324 then Gl.disable `blend
;
1327 let s = Printf.sprintf
1331 let w = measurestr
fstate.fontsize
s in
1332 GlMisc.push_attrib
[`current
];
1333 GlDraw.color
(0.0, 0.0, 0.0);
1335 (float (x-2), float (y-2))
1336 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1337 GlDraw.color
(1.0, 1.0, 1.0);
1338 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1339 GlMisc.pop_attrib
();
1344 let lw = conf.winw
- state.scrollw
- x in
1347 let lh = conf.winh
- y in
1350 Gl.enable `texture_2d
;
1351 begin match state.texid
with
1353 GlTex.bind_texture `texture_2d id
;
1356 and x1 = float (x+w)
1357 and y1 = float (y+h) in
1359 let tw = float w /. 64.0
1360 and th
= float h /. 64.0 in
1361 let tx0 = float tilex /. 64.0
1362 and ty0
= float tiley /. 64.0 in
1364 and ty1
= ty0
+. th
in
1365 GlDraw.begins `quads
;
1366 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1367 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1368 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1369 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1372 Gl.disable `texture_2d
;
1374 GlDraw.color
(1.0, 1.0, 1.0);
1377 (float (x+w), float (y+h));
1379 if w > 128 && h > fstate.fontsize
+ 10
1381 GlDraw.color
(0.0, 0.0, 0.0);
1384 then (col*conf.tilew
, row*conf.tileh
)
1387 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1394 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1396 let tilevisible1 l
x y =
1398 and ax1
= l
.pagex + l
.pagevw
1400 and ay1
= l
.pagey + l
.pagevh in
1404 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1405 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1407 let rx0 = max
ax0 bx0
1408 and ry0
= max ay0 by0
1409 and rx1
= min ax1
bx1
1410 and ry1
= min ay1 by1
in
1412 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1413 nonemptyintersection
1416 let tilevisible layout n x y =
1417 let rec findpageinlayout m
= function
1418 | l
:: rest
when l
.pageno
= n ->
1419 tilevisible1 l
x y || (
1420 match conf.columns
with
1421 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1424 | _
:: rest
-> findpageinlayout 0 rest
1427 findpageinlayout 0 layout;
1430 let tileready l
x y =
1431 tilevisible1 l
x y &&
1432 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1435 let tilepage n p
layout =
1436 let rec loop = function
1440 let f col row _ _ _ _ _ _
=
1441 if state.currently
= Idle
1443 match gettileopaque l
col row with
1446 let x = col*conf.tilew
1447 and y = row*conf.tileh
in
1449 let w = l
.pagew
- x in
1453 let h = l
.pageh
- y in
1456 wcmd "tile %s %d %d %d %d" p
x y w h;
1459 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1460 conf.tilew
, conf.tileh
1469 if nogeomcmds state.geomcmds
1473 let preloadlayout visiblepages
=
1474 let presentation = conf.presentation in
1475 let interpagespace = conf.interpagespace in
1476 let maxy = state.maxy in
1477 conf.presentation <- false;
1478 conf.interpagespace <- 0;
1479 state.maxy <- calcheight ();
1481 match visiblepages
with
1483 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1485 let y = if y < conf.winh
then 0 else y - conf.winh
in
1486 let h = state.y - y + conf.winh
*3 in
1487 let pages = layout y h in
1488 conf.presentation <- presentation;
1489 conf.interpagespace <- interpagespace;
1495 let rec loop pages =
1496 if state.currently
!= Idle
1501 begin match getopaque l
.pageno
with
1503 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1504 state.currently
<- Loading
(l
, state.gen
);
1506 tilepage l
.pageno opaque
pages;
1511 if nogeomcmds state.geomcmds
1517 if conf.preload && state.currently
= Idle
1518 then load (preloadlayout pages);
1521 let layoutready layout =
1522 let rec fold all ls
=
1523 all
&& match ls
with
1525 let seen = ref false in
1526 let allvisible = ref true in
1527 let foo col row _ _ _ _ _ _
=
1529 allvisible := !allvisible &&
1530 begin match gettileopaque l
col row with
1536 fold (!seen && !allvisible) rest
1539 let alltilesvisible = fold true layout in
1544 let y = bound y 0 state.maxy in
1545 let y, layout, proceed
=
1546 match conf.maxwait
with
1547 | Some time
when state.ghyll
== noghyll ->
1548 begin match state.throttle
with
1550 let layout = layout y conf.winh
in
1551 let ready = layoutready layout in
1555 state.throttle
<- Some
(layout, y, now ());
1557 else G.postRedisplay "gotoy showall (None)";
1559 | Some
(_
, _
, started
) ->
1560 let dt = now () -. started
in
1563 state.throttle
<- None
;
1564 let layout = layout y conf.winh
in
1566 G.postRedisplay "maxwait";
1573 let layout = layout y conf.winh
in
1574 if true || layoutready layout
1575 then G.postRedisplay "gotoy ready";
1581 state.layout <- layout;
1582 begin match state.mode
with
1583 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1584 let rec loop = function
1586 state.mode
<- LinkNav
(Ltgendir
0)
1587 | l
:: _
when l
.pageno
= pageno
->
1588 begin match getopaque pageno
with
1590 state.mode
<- LinkNav
(Ltgendir
0)
1592 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1593 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1594 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1595 then state.mode
<- LinkNav
(Ltgendir
0)
1597 | _
:: rest
-> loop rest
1602 begin match state.mode
with
1603 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1604 if not
(pagevisible layout pageno
)
1606 match state.layout with
1609 state.mode
<- Birdseye
(
1610 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1613 | LinkNav
(Ltgendir dir
as lt
) ->
1615 let rec loop = function
1618 match getopaque l
.pageno
with
1624 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1626 if dir
> 0 then LDfirst
else LDlast
1632 | Lnotfound
-> loop rest
1634 showlinktype (getlink opaque
n);
1635 Ltexact
(l
.pageno
, n)
1639 state.mode
<- LinkNav
linknav
1644 state.ghyll
<- noghyll;
1647 let mx, my
= state.mpos
in
1652 let conttiling pageno opaque
=
1653 tilepage pageno opaque
1654 (if conf.preload then preloadlayout state.layout else state.layout)
1657 let gotoy_and_clear_text y =
1658 if not
conf.verbose
then state.text <- "";
1663 match state.layout with
1665 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1668 let getanchory (n, top
) =
1669 let y, h = getpageyh n in
1670 y + (truncate
(top
*. float h));
1673 let gotoanchor anchor
=
1674 gotoy (getanchory anchor
);
1678 cbput state.hists
.nav
(getanchor ());
1682 let anchor = cbgetc state.hists
.nav dir
in
1687 let rec scroll f n a
b =
1688 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1690 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1692 then s (float f /. float a
)
1695 then 1.0 -. s ((float (f-b) /. float (n-b)))
1702 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1703 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1705 let ins = float a
*. iv1
1706 and outs
= float (n-b) *. iv1 in
1708 ins +. outs
+. float ones
1710 let rec set (_N
, _A
, _B
) y sy
=
1711 let sum = summa
1.0 _N _A _B
in
1712 let dy = float (y - sy
) in
1716 then state.ghyll
<- noghyll
1719 let s = scroll n _N _A _B
in
1720 let y1 = y1 +. ((s *. dy) /. sum) in
1721 gotoy_and_clear_text (truncate
y1);
1722 state.ghyll
<- gf (n+1) y1;
1726 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1728 gf 0 (float state.y)
1731 match conf.ghyllscroll
with
1733 gotoy_and_clear_text y
1735 if state.ghyll
== noghyll
1736 then set nab
y state.y
1737 else state.ghyll
(Some
y)
1740 let gotopage n top
=
1741 let y, h = getpageyh n in
1742 let y = y + (truncate
(top
*. float h)) in
1746 let gotopage1 n top
=
1747 let y = getpagey n in
1752 let invalidate s f =
1757 match state.geomcmds
with
1758 | ps
, [] when String.length ps
= 0 ->
1760 state.geomcmds
<- s, [];
1763 state.geomcmds
<- ps
, [s, f];
1765 | ps
, (s'
, _
) :: rest
when s'
= s ->
1766 state.geomcmds
<- ps
, ((s, f) :: rest
);
1769 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1772 let opendoc path password
=
1774 state.password
<- password
;
1775 state.gen
<- state.gen
+ 1;
1776 state.docinfo
<- [];
1778 setaalevel
conf.aalevel
;
1779 Wsi.settitle
("llpp " ^
Filename.basename path
);
1780 wcmd "open %s\000%s\000" path password
;
1781 invalidate "reqlayout"
1783 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1787 let c = c *. conf.colorscale
in
1791 let scalecolor2 (r
, g
, b) =
1792 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1796 let docolumns = function
1799 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1800 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1801 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1802 if pageno
= state.pagecount
1805 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1807 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1808 pdimno+1, pdim
, rest
1813 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1815 (conf.winw
- state.scrollw
- w) / 2,
1816 y + rowh
+ conf.interpagespace, h
1819 if (pageno
- coverA
) mod columns
= 0
1820 then 0, y + rowh
+ conf.interpagespace, h
1821 else x, y, max rowh
h
1824 let rec fixrow m
= if m
= pageno
then () else
1825 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1828 let y = y + (rowh
- h) / 2 in
1829 a.(m
) <- (pdimno, x, y, pdim
);
1833 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1834 then fixrow (pageno
- columns
);
1835 a.(pageno
) <- (pdimno, x, y, pdim
);
1836 let x = x + w + xoff*2 + conf.interpagespace in
1837 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1839 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1840 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1843 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1844 let rec loop pageno
pdimno pdim
y pdims
=
1845 if pageno
= state.pagecount
1848 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1850 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1851 pdimno+1, pdim
, rest
1856 let rec loop1 n x y =
1857 if n = c then y else (
1858 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1859 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1862 let y = loop1 0 0 y in
1863 loop (pageno
+1) pdimno pdim
y pdims
1865 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1866 conf.columns
<- Csplit
(c, a);
1868 docolumns conf.columns
;
1869 state.maxy <- calcheight ();
1871 if state.w <= conf.winw
- state.scrollw
1875 match state.mode
with
1876 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1877 let y, h = getpageyh pageno
in
1878 let top = (conf.winh
- h) / 2 in
1879 gotoy (max
0 (y - top))
1880 | _
-> gotoanchor state.anchor
1884 GlDraw.viewport
0 0 w h;
1885 let firsttime = state.geomcmds
== firstgeomcmds in
1886 if not
firsttime && nogeomcmds state.geomcmds
1887 then state.anchor <- getanchor ();
1890 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1893 setfontsize fstate.fontsize
;
1894 GlMat.mode `modelview
;
1895 GlMat.load_identity
();
1897 GlMat.mode `projection
;
1898 GlMat.load_identity
();
1899 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1900 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1901 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1906 else float state.x /. float state.w
1908 invalidate "geometry"
1912 then state.x <- truncate
(relx *. float w);
1914 match conf.columns
with
1916 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
1917 | Csplit
(c, _
) -> w * c
1919 wcmd "geometry %d %d" w h);
1923 let len = String.length
state.text in
1926 match state.mode
with
1928 | View
-> state.hscrollh
1933 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1934 (x+.w, float (conf.winh
- hscrollh))
1937 let w = float (conf.winw
- state.scrollw
- 1) in
1938 if state.progress
>= 0.0 && state.progress
< 1.0
1940 GlDraw.color
(0.3, 0.3, 0.3);
1941 let w1 = w *. state.progress
in
1943 GlDraw.color
(0.0, 0.0, 0.0);
1947 GlDraw.color
(0.0, 0.0, 0.0);
1951 GlDraw.color
(1.0, 1.0, 1.0);
1952 drawstring fstate.fontsize
1953 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1956 match state.mode
with
1957 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1961 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1963 Printf.sprintf
"%s%s_" prefix
text
1972 if not
(istextentry state.mode
)
1974 let s1 = "(press 'e' to review error messasges)" in
1975 if String.length
s > 0 then s ^
" " ^
s1 else s1
1980 if String.length
s > 0
1985 let len = Queue.length
state.tilelru
in
1987 if state.memused
<= conf.memlimit
1992 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1993 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1994 let (_
, pw, ph
, _
) = getpagedim n in
1997 && colorspace
= conf.colorspace
1998 && angle
= conf.angle
2003 match state.throttle
with
2006 then preloadlayout state.layout
2008 | Some
(layout, _
, _
) ->
2011 let x = col*conf.tilew
2012 and y = row*conf.tileh
in
2013 tilevisible layout n x y
2015 then Queue.push lruitem
state.tilelru
2017 wcmd "freetile %s" p
;
2018 state.memused
<- state.memused
- s;
2019 state.uioh#infochanged Memused
;
2020 Hashtbl.remove
state.tilemap k
;
2029 Queue.iter
(fun (k
, p
, s) ->
2030 wcmd "freetile %s" p
;
2031 state.memused
<- state.memused
- s;
2032 state.uioh#infochanged Memused
;
2033 Hashtbl.remove
state.tilemap k
;
2035 Queue.clear
state.tilelru
;
2039 let logcurrently = function
2040 | Idle
-> dolog "Idle"
2041 | Loading
(l
, gen
) ->
2042 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2043 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2045 "Tiling %d[%d,%d] page=%s cs=%s angle"
2046 l
.pageno
col row pageopaque
2047 (colorspace_to_string colorspace
)
2049 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2050 angle gen
conf.angle
state.gen
2052 conf.tilew
conf.tileh
2059 (* dolog "%S" cmds; *)
2062 try String.index cmds ' '
2063 with Not_found
-> -1
2068 let l = String.length cmds
in
2069 let op = String.sub cmds
0 spacepos in
2071 if l - spacepos < 2 then ""
2072 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2077 state.uioh#infochanged Pdim
;
2081 state.rects
<- state.rects1
;
2082 G.postRedisplay "clearrects";
2086 try Scanf.sscanf args
"%u" (fun n -> n)
2088 dolog "error processing 'continue' %S: %s"
2089 cmds
(Printexc.to_string exn
);
2092 state.pagecount
<- n;
2093 begin match state.currently
with
2095 state.currently
<- Idle
;
2096 state.outlines
<- Array.of_list
(List.rev
l)
2100 let cur, cmds
= state.geomcmds
in
2101 if String.length
cur = 0
2102 then failwith
"umpossible";
2104 begin match List.rev cmds
with
2106 state.geomcmds
<- "", [];
2110 state.geomcmds
<- s, List.rev rest
;
2112 if conf.maxwait
= None
2113 then G.postRedisplay "continue";
2123 then showtext ' ' args
2126 let progress, text =
2128 Scanf.sscanf args
"%f %n"
2130 f, String.sub args pos
(String.length args
- pos
))
2132 dolog "error processing 'progress' %S: %s"
2133 cmds
(Printexc.to_string exn
);
2137 state.progress <- progress;
2138 G.postRedisplay "progress"
2141 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2143 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
2144 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2145 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2147 dolog "error processing 'firstmatch' %S: %s"
2148 cmds
(Printexc.to_string exn
);
2151 let y = (getpagey pageno) + truncate
y0 in
2154 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2157 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2159 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
2160 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2161 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2163 dolog "error processing 'match' %S: %s"
2164 cmds
(Printexc.to_string exn
);
2168 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2173 Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
)
2175 dolog "error processing 'page' %S: %s"
2176 cmds
(Printexc.to_string exn
);
2179 begin match state.currently
with
2180 | Loading
(l, gen
) ->
2181 vlog "page %d took %f sec" l.pageno t
;
2182 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2183 begin match state.throttle
with
2185 let preloadedpages =
2187 then preloadlayout state.layout
2192 Set.Make
(struct type t
= int let compare = (-) end) in
2194 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2195 IntSet.empty
preloadedpages
2198 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2199 if not
(IntSet.mem
pageno set)
2201 wcmd "freepage %s" opaque
;
2207 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2210 state.currently
<- Idle
;
2213 tilepage l.pageno pageopaque state.layout;
2215 load preloadedpages;
2216 if pagevisible state.layout l.pageno
2217 && layoutready state.layout
2218 then G.postRedisplay "page";
2221 | Some
(layout, _
, _
) ->
2222 state.currently
<- Idle
;
2223 tilepage l.pageno pageopaque layout;
2228 dolog "Inconsistent loading state";
2229 logcurrently state.currently
;
2234 let (x, y, opaque
, size
, t
) =
2236 Scanf.sscanf args
"%u %u %s %u %f"
2237 (fun x y p size t
-> (x, y, p
, size
, t
))
2239 dolog "error processing 'tile' %S: %s"
2240 cmds
(Printexc.to_string exn
);
2243 begin match state.currently
with
2244 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2245 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2247 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2249 wcmd "freetile %s" opaque
;
2250 state.currently
<- Idle
;
2254 puttileopaque l col row gen cs angle opaque size t
;
2255 state.memused
<- state.memused
+ size
;
2256 state.uioh#infochanged Memused
;
2258 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2259 opaque
, size
) state.tilelru
;
2262 match state.throttle
with
2263 | None
-> state.layout
2264 | Some
(layout, _
, _
) -> layout
2267 state.currently
<- Idle
;
2269 && conf.colorspace
= cs
2270 && conf.angle
= angle
2271 && tilevisible layout l.pageno x y
2272 then conttiling l.pageno pageopaque;
2274 begin match state.throttle
with
2276 preload state.layout;
2278 && conf.colorspace
= cs
2279 && conf.angle
= angle
2280 && tilevisible state.layout l.pageno x y
2281 then G.postRedisplay "tile nothrottle";
2283 | Some
(layout, y, _
) ->
2284 let ready = layoutready layout in
2288 state.layout <- layout;
2289 state.throttle
<- None
;
2290 G.postRedisplay "throttle";
2297 dolog "Inconsistent tiling state";
2298 logcurrently state.currently
;
2305 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
2307 dolog "error processing 'pdim' %S: %s"
2308 cmds
(Printexc.to_string exn
);
2311 state.uioh#infochanged Pdim
;
2312 state.pdims
<- pdim :: state.pdims
2315 let (l, n, t
, h, pos
) =
2317 Scanf.sscanf args
"%u %u %d %u %n"
2318 (fun l n t
h pos
-> l, n, t
, h, pos
)
2320 dolog "error processing 'o' %S: %s"
2321 cmds
(Printexc.to_string exn
);
2324 let s = String.sub args pos
(String.length args
- pos
) in
2325 let outline = (s, l, (n, float t
/. float h)) in
2326 begin match state.currently
with
2327 | Outlining outlines
->
2328 state.currently
<- Outlining
(outline :: outlines
)
2330 state.currently
<- Outlining
[outline]
2332 dolog "invalid outlining state";
2333 logcurrently currently
2337 state.docinfo
<- (1, args
) :: state.docinfo
2340 state.uioh#infochanged Docinfo
;
2341 state.docinfo
<- List.rev
state.docinfo
2344 dolog "unknown cmd `%S'" cmds
2349 let action = function
2350 | HCprev
-> cbget cb ~
-1
2351 | HCnext
-> cbget cb
1
2352 | HCfirst
-> cbget cb ~
-(cb
.rc)
2353 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2354 and cancel
() = cb
.rc <- rc
2358 let search pattern forward
=
2359 if String.length pattern
> 0
2362 match state.layout with
2365 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2367 wcmd "search %d %d %d %d,%s\000"
2368 (btod conf.icase
) pn py (btod forward
) pattern
;
2371 let intentry text key =
2373 if key >= 32 && key < 127
2379 let text = addchar text c in
2383 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2387 let textentry text key =
2388 if key land 0xff00 = 0xff00
2390 else TEcont
(text ^
Wsi.toutf8
key)
2393 let reqlayout angle proportional
=
2394 match state.throttle
with
2396 if nogeomcmds state.geomcmds
2397 then state.anchor <- getanchor ();
2398 conf.angle
<- angle
mod 360;
2401 match state.mode
with
2402 | LinkNav _
-> state.mode
<- View
2405 conf.proportional
<- proportional
;
2406 invalidate "reqlayout"
2407 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2411 let settrim trimmargins trimfuzz
=
2412 if nogeomcmds state.geomcmds
2413 then state.anchor <- getanchor ();
2414 conf.trimmargins
<- trimmargins
;
2415 conf.trimfuzz
<- trimfuzz
;
2416 let x0, y0, x1, y1 = trimfuzz
in
2417 invalidate "settrim"
2419 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2420 Hashtbl.iter
(fun _ opaque
->
2421 wcmd "freepage %s" opaque
;
2423 Hashtbl.clear
state.pagemap
;
2427 match state.throttle
with
2429 let zoom = max
0.01 zoom in
2430 if zoom <> conf.zoom
2432 state.prevzoom
<- conf.zoom;
2434 reshape conf.winw
conf.winh
;
2435 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2438 | Some
(layout, y, started
) ->
2440 match conf.maxwait
with
2444 let dt = now () -. started
in
2452 let setcolumns mode columns coverA coverB
=
2456 then showtext '
!'
"split mode doesn't work in bird's eye"
2458 conf.columns
<- Csplit
(-columns
, [||]);
2466 conf.columns
<- Csingle
;
2471 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2475 reshape conf.winw
conf.winh
;
2478 let enterbirdseye () =
2479 let zoom = float conf.thumbw
/. float conf.winw
in
2480 let birdseyepageno =
2481 let cy = conf.winh
/ 2 in
2485 let rec fold best
= function
2488 let d = cy - (l.pagedispy + l.pagevh/2)
2489 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2490 if abs
d < abs dbest
2497 state.mode
<- Birdseye
(
2498 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2501 conf.presentation <- false;
2502 conf.interpagespace <- 10;
2503 conf.hlinks
<- false;
2505 state.mstate
<- Mnone
;
2506 conf.maxwait
<- None
;
2508 match conf.beyecolumns
with
2511 Cmulti
((c, 0, 0), [||])
2514 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2517 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2522 reshape conf.winw
conf.winh
;
2525 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2527 conf.zoom <- c.zoom;
2528 conf.presentation <- c.presentation;
2529 conf.interpagespace <- c.interpagespace;
2530 conf.maxwait
<- c.maxwait
;
2531 conf.hlinks
<- c.hlinks
;
2532 conf.beyecolumns
<- (
2533 match conf.columns
with
2534 | Cmulti
((c, _
, _
), _
) -> Some
c
2536 | Csplit _
-> assert false
2539 match c.columns
with
2540 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2541 | Csingle
-> Csingle
2542 | Csplit _
-> failwith
"leaving bird's eye split mode"
2547 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2550 reshape conf.winw
conf.winh
;
2551 state.anchor <- if goback
then anchor else (pageno, 0.0);
2554 let togglebirdseye () =
2555 match state.mode
with
2556 | Birdseye vals
-> leavebirdseye vals
true
2557 | View
-> enterbirdseye ()
2561 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2562 let pageno = max
0 (pageno - incr
) in
2563 let rec loop = function
2564 | [] -> gotopage1 pageno 0
2565 | l :: _
when l.pageno = pageno ->
2566 if l.pagedispy >= 0 && l.pagey = 0
2567 then G.postRedisplay "upbirdseye"
2568 else gotopage1 pageno 0
2569 | _
:: rest
-> loop rest
2572 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2575 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2576 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2577 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2578 let rec loop = function
2580 let y, h = getpageyh pageno in
2581 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2583 | l :: _
when l.pageno = pageno ->
2584 if l.pagevh != l.pageh
2585 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2586 else G.postRedisplay "downbirdseye"
2587 | _
:: rest
-> loop rest
2592 let optentry mode _
key =
2593 let btos b = if b then "on" else "off" in
2594 if key >= 32 && key < 127
2596 let c = Char.chr
key in
2600 try conf.scrollstep
<- int_of_string
s with exc
->
2601 state.text <- Printf.sprintf
"bad integer `%s': %s"
2602 s (Printexc.to_string exc
)
2604 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2609 conf.autoscrollstep
<- int_of_string
s;
2610 if state.autoscroll
<> None
2611 then state.autoscroll
<- Some
conf.autoscrollstep
2613 state.text <- Printf.sprintf
"bad integer `%s': %s"
2614 s (Printexc.to_string exc
)
2616 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2619 let mode = state.mode in
2622 let n, a, b = multicolumns_of_string s in
2623 setcolumns mode n a b;
2625 state.text <- Printf.sprintf
"bad columns `%s': %s"
2626 s (Printexc.to_string exc
)
2628 TEswitch
("columns: ", "", None
, textentry, ondone)
2633 let zoom = float (int_of_string
s) /. 100.0 in
2636 state.text <- Printf.sprintf
"bad integer `%s': %s"
2637 s (Printexc.to_string exc
)
2639 TEswitch
("zoom: ", "", None
, intentry, ondone)
2644 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2646 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2647 begin match mode with
2649 leavebirdseye beye
false;
2654 state.text <- Printf.sprintf
"bad integer `%s': %s"
2655 s (Printexc.to_string exc
)
2657 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2662 Some
(int_of_string
s)
2664 state.text <- Printf.sprintf
"bad integer `%s': %s"
2665 s (Printexc.to_string exc
);
2668 | Some angle
-> reqlayout angle
conf.proportional
2671 TEswitch
("rotation: ", "", None
, intentry, ondone)
2674 conf.icase
<- not
conf.icase
;
2675 TEdone
("case insensitive search " ^
(btos conf.icase
))
2678 conf.preload <- not
conf.preload;
2680 TEdone
("preload " ^
(btos conf.preload))
2683 conf.verbose
<- not
conf.verbose
;
2684 TEdone
("verbose " ^
(btos conf.verbose
))
2687 conf.debug
<- not
conf.debug
;
2688 TEdone
("debug " ^
(btos conf.debug
))
2691 conf.maxhfit
<- not
conf.maxhfit
;
2693 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2694 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2697 conf.crophack
<- not
conf.crophack
;
2698 TEdone
("crophack " ^
btos conf.crophack
)
2702 match conf.maxwait
with
2704 conf.maxwait
<- Some infinity
;
2705 "always wait for page to complete"
2707 conf.maxwait
<- None
;
2708 "show placeholder if page is not ready"
2713 conf.underinfo
<- not
conf.underinfo
;
2714 TEdone
("underinfo " ^
btos conf.underinfo
)
2717 conf.savebmarks
<- not
conf.savebmarks
;
2718 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2724 match state.layout with
2729 conf.interpagespace <- int_of_string
s;
2730 state.maxy <- calcheight ();
2731 let y = getpagey pageno in
2734 state.text <- Printf.sprintf
"bad integer `%s': %s"
2735 s (Printexc.to_string exc
)
2737 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2740 reqlayout conf.angle
(not
conf.proportional
);
2741 TEdone
("proportional display " ^
btos conf.proportional
)
2744 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2745 TEdone
("trim margins " ^
btos conf.trimmargins
)
2748 conf.invert
<- not
conf.invert
;
2749 TEdone
("invert colors " ^
btos conf.invert
)
2753 cbput state.hists
.sel
s;
2756 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2760 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2766 class type lvsource
= object
2767 method getitemcount
: int
2768 method getitem
: int -> (string * int)
2769 method hasaction
: int -> bool
2778 method getactive
: int
2779 method getfirst
: int
2780 method getqsearch
: string
2781 method setqsearch
: string -> unit
2785 class virtual lvsourcebase
= object
2786 val mutable m_active
= 0
2787 val mutable m_first
= 0
2788 val mutable m_qsearch
= ""
2789 val mutable m_pan
= 0
2790 method getactive
= m_active
2791 method getfirst
= m_first
2792 method getqsearch
= m_qsearch
2793 method getpan
= m_pan
2794 method setqsearch
s = m_qsearch
<- s
2797 let withoutlastutf8 s =
2798 let len = String.length
s in
2806 let b = Char.code
s.[pos
] in
2807 if b land 0b110000 = 0b11000000
2812 if Char.code
s.[len-1] land 0x80 = 0
2816 String.sub
s 0 first;
2819 let textentrykeyboard key _mask
((c, text, opthist
, onkey
, ondone), onleave
) =
2821 state.mode <- Textentry
(te
, onleave
);
2824 G.postRedisplay "textentrykeyboard enttext";
2826 let histaction cmd
=
2829 | Some
(action, _
) ->
2830 state.mode <- Textentry
(
2831 (c, action cmd
, opthist
, onkey
, ondone), onleave
2833 G.postRedisplay "textentry histaction"
2836 | 0xff08 -> (* backspace *)
2837 let s = withoutlastutf8 text in
2838 let len = String.length
s in
2842 G.postRedisplay "textentrykeyboard after cancel";
2845 enttext (c, s, opthist
, onkey
, ondone)
2851 G.postRedisplay "textentrykeyboard after confirm"
2853 | 0xff52 -> histaction HCprev
2854 | 0xff54 -> histaction HCnext
2855 | 0xff50 -> histaction HCfirst
2856 | 0xff57 -> histaction HClast
2858 | 0xff1b -> (* escape*)
2859 if String.length
text = 0
2861 begin match opthist
with
2863 | Some
(_
, onhistcancel
) -> onhistcancel
()
2867 G.postRedisplay "textentrykeyboard after cancel2"
2870 enttext (c, "", opthist
, onkey
, ondone)
2873 | 0xff9f | 0xffff -> () (* delete *)
2875 | _
when key != 0 && key land 0xff00 != 0xff00 ->
2876 begin match onkey
text key with
2880 G.postRedisplay "textentrykeyboard after confirm2";
2883 enttext (c, text, opthist
, onkey
, ondone);
2887 G.postRedisplay "textentrykeyboard after cancel3"
2890 state.mode <- Textentry
(te
, onleave
);
2891 G.postRedisplay "textentrykeyboard switch";
2895 vlog "unhandled key %s" (Wsi.keyname
key)
2898 let firstof first active
=
2899 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
2900 then max
0 (active
- (fstate.maxrows
/2))
2904 let calcfirst first active
=
2907 let rows = active
- first in
2908 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2912 let scrollph y maxy =
2913 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2914 let sh = float conf.winh
/. sh in
2915 let sh = max
sh (float conf.scrollh
) in
2920 else float y /. float maxy
2922 let position = (float conf.winh
-. sh) *. percent in
2925 if position +. sh > float conf.winh
2926 then float conf.winh
-. sh
2932 let coe s = (s :> uioh
);;
2934 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
2936 val m_pan
= source#getpan
2937 val m_first
= source#getfirst
2938 val m_active
= source#getactive
2939 val m_qsearch
= source#getqsearch
2940 val m_prev_uioh
= state.uioh
2942 method private elemunder
y =
2943 let n = y / (fstate.fontsize
+1) in
2944 if m_first
+ n < source#getitemcount
2946 if source#hasaction
(m_first
+ n)
2947 then Some
(m_first
+ n)
2954 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2955 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2956 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2957 GlDraw.color
(1., 1., 1.);
2958 Gl.enable `texture_2d
;
2959 let fs = fstate.fontsize
in
2961 let ww = fstate.wwidth
in
2962 let tabw = 30.0*.ww in
2963 let itemcount = source#getitemcount
in
2965 if (row - m_first
) * nfs > conf.winh
2968 if row >= 0 && row < itemcount
2970 let (s, level
) = source#getitem
row in
2971 let y = (row - m_first
) * nfs in
2972 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2975 Gl.disable `texture_2d
;
2976 GlDraw.polygon_mode `both `line
;
2977 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2978 GlDraw.rect (1., float (y + 1))
2979 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2980 GlDraw.polygon_mode `both `fill
;
2981 GlDraw.color
(1., 1., 1.);
2982 Gl.enable `texture_2d
;
2985 let drawtabularstring s =
2986 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2989 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2992 let len = String.length
s - tabpos - 1 in
2993 let s1 = String.sub
s 0 tabpos
2994 and s2
= String.sub
s (tabpos + 1) len in
2995 let nx = drawstr x s1 in
2997 let x = x +. (max
tabw sw) in
3004 let _ = drawtabularstring s in
3011 Gl.disable `texture_2d
;
3013 method updownlevel incr
=
3014 let len = source#getitemcount
in
3016 if m_active
>= 0 && m_active
< len
3017 then snd
(source#getitem m_active
)
3021 if i
= len then i
-1 else if i
= -1 then 0 else
3022 let _, l = source#getitem i
in
3023 if l != curlevel then i
else flow (i
+incr
)
3025 let active = flow m_active
in
3026 let first = calcfirst m_first
active in
3027 G.postRedisplay "outline updownlevel";
3028 {< m_active
= active; m_first
= first >}
3030 method private key1
key mask
=
3031 let set1 active first qsearch
=
3032 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3034 let search active pattern incr
=
3037 if n >= 0 && n < source#getitemcount
3039 let s, _ = source#getitem
n in
3041 (try ignore
(Str.search_forward
re s 0); true
3042 with Not_found
-> false)
3044 else loop (n + incr
)
3051 let re = Str.regexp_case_fold pattern
in
3057 let itemcount = source#getitemcount
in
3058 let find start incr
=
3060 if i
= -1 || i
= itemcount
3063 if source#hasaction i
3065 else find (i
+ incr
)
3070 let set active first =
3071 let first = bound first 0 (itemcount - fstate.maxrows
) in
3073 coe {< m_active
= active; m_first
= first >}
3076 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3078 let incr1 = if incr
> 0 then 1 else -1 in
3079 if isvisible m_first m_active
3082 let next = m_active
+ incr
in
3084 if next < 0 || next >= itemcount
3086 else find next incr1
3088 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3094 let first = m_first
+ incr
in
3095 let first = bound first 0 (itemcount - 1) in
3097 let next = m_active
+ incr
in
3098 let next = bound next 0 (itemcount - 1) in
3101 let active = if next = -1 then m_active
else next in
3104 let first = min
next m_first
in
3106 if abs
(next - first) > fstate.maxrows
3112 let first = m_first
+ incr
in
3113 let first = bound first 0 (itemcount - 1) in
3115 let next = m_active
+ incr
in
3116 let next = bound next 0 (itemcount - 1) in
3117 let next = find next incr1 in
3119 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3121 let active = if m_active
= -1 then next else m_active
in
3126 if isvisible first active
3132 G.postRedisplay "listview navigate";
3136 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3137 let incr = if key = 0x72 then -1 else 1 in
3139 match search (m_active
+ incr) m_qsearch
incr with
3141 state.text <- m_qsearch ^
" [not found]";
3144 state.text <- m_qsearch
;
3145 active, firstof m_first
active
3147 G.postRedisplay "listview ctrl-r/s";
3148 set1 active first m_qsearch
;
3150 | 0xff08 -> (* backspace *)
3151 if String.length m_qsearch
= 0
3154 let qsearch = withoutlastutf8 m_qsearch
in
3155 let len = String.length
qsearch in
3159 G.postRedisplay "listview empty qsearch";
3160 set1 m_active m_first
"";
3164 match search m_active
qsearch ~
-1 with
3166 state.text <- qsearch ^
" [not found]";
3169 state.text <- qsearch;
3170 active, firstof m_first
active
3172 G.postRedisplay "listview backspace qsearch";
3173 set1 active first qsearch
3176 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3177 let pattern = m_qsearch ^
Wsi.toutf8
key in
3179 match search m_active
pattern 1 with
3181 state.text <- pattern ^
" [not found]";
3184 state.text <- pattern;
3185 active, firstof m_first
active
3187 G.postRedisplay "listview qsearch add";
3188 set1 active first pattern;
3190 | 0xff1b -> (* escape *)
3192 if String.length m_qsearch
= 0
3194 G.postRedisplay "list view escape";
3197 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3199 | None
-> m_prev_uioh
3204 G.postRedisplay "list view kill qsearch";
3205 source#setqsearch
"";
3206 coe {< m_qsearch
= "" >}
3209 | 0xff0d -> (* return *)
3211 let self = {< m_qsearch
= "" >} in
3212 source#setqsearch
"";
3214 G.postRedisplay "listview enter";
3215 if m_active
>= 0 && m_active
< source#getitemcount
3217 source#exit
(coe self) false m_active m_first m_pan
"";
3220 source#exit
(coe self) true m_active m_first m_pan
"";
3223 begin match opt with
3224 | None
-> m_prev_uioh
3228 | 0xff9f | 0xffff -> (* delete *)
3231 | 0xff52 -> navigate ~
-1 (* up *)
3232 | 0xff54 -> navigate 1 (* down *)
3233 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3234 | 0xff56 -> navigate fstate.maxrows
(* next *)
3236 | 0xff53 -> (* right *)
3238 G.postRedisplay "listview right";
3239 coe {< m_pan
= m_pan
- 1 >}
3241 | 0xff51 -> (* left *)
3243 G.postRedisplay "listview left";
3244 coe {< m_pan
= m_pan
+ 1 >}
3246 | 0xff50 -> (* home *)
3247 let active = find 0 1 in
3248 G.postRedisplay "listview home";
3251 | 0xff57 -> (* end *)
3252 let first = max
0 (itemcount - fstate.maxrows
) in
3253 let active = find (itemcount - 1) ~
-1 in
3254 G.postRedisplay "listview end";
3257 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3261 dolog "listview unknown key %#x" key; coe self
3263 method key key mask
=
3264 match state.mode with
3265 | Textentry te
-> textentrykeyboard key mask te
; coe self
3266 | _ -> self#key1
key mask
3268 method button button down
x y _ =
3271 | 1 when x > conf.winw
- conf.scrollbw
->
3272 G.postRedisplay "listview scroll";
3275 let _, position, sh = self#
scrollph in
3276 if y > truncate
position && y < truncate
(position +. sh)
3278 state.mstate
<- Mscrolly
;
3282 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3283 let first = truncate
(s *. float source#getitemcount
) in
3284 let first = min source#getitemcount
first in
3285 Some
(coe {< m_first
= first; m_active
= first >})
3287 state.mstate
<- Mnone
;
3290 | 1 when not down
->
3291 begin match self#elemunder
y with
3293 G.postRedisplay "listview click";
3295 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3299 | n when (n == 4 || n == 5) && not down
->
3300 let len = source#getitemcount
in
3302 if n = 5 && m_first
+ fstate.maxrows
>= len
3306 let first = m_first
+ (if n == 4 then -1 else 1) in
3307 bound first 0 (len - 1)
3309 G.postRedisplay "listview wheel";
3310 Some
(coe {< m_first
= first >})
3315 | None
-> m_prev_uioh
3319 match state.mstate
with
3321 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3322 let first = truncate
(s *. float source#getitemcount
) in
3323 let first = min source#getitemcount
first in
3324 G.postRedisplay "listview motion";
3325 coe {< m_first
= first; m_active
= first >}
3328 method pmotion
x y =
3329 if x < conf.winw
- conf.scrollbw
3332 match self#elemunder
y with
3333 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3334 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3338 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3343 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3347 method infochanged
_ = ()
3349 method scrollpw
= (0, 0.0, 0.0)
3351 let nfs = fstate.fontsize
+ 1 in
3352 let y = m_first
* nfs in
3353 let itemcount = source#getitemcount
in
3354 let maxi = max
0 (itemcount - fstate.maxrows
) in
3355 let maxy = maxi * nfs in
3356 let p, h = scrollph y maxy in
3359 method modehash
= modehash
3362 class outlinelistview ~source
=
3365 ~source
:(source
:> lvsource
)
3367 ~modehash
:(findkeyhash conf "outline")
3370 method key key mask
=
3371 let calcfirst first active =
3374 let rows = active - first in
3375 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3379 let active = m_active
+ incr in
3380 let active = bound active 0 (source#getitemcount
- 1) in
3381 let first = calcfirst m_first
active in
3382 G.postRedisplay "outline navigate";
3383 coe {< m_active
= active; m_first
= first >}
3385 let ctrl = Wsi.withctrl mask
in
3387 | 110 when ctrl -> (* ctrl-n *)
3388 source#narrow m_qsearch
;
3389 G.postRedisplay "outline ctrl-n";
3390 coe {< m_first
= 0; m_active
= 0 >}
3392 | 117 when ctrl -> (* ctrl-u *)
3394 G.postRedisplay "outline ctrl-u";
3396 coe {< m_first
= 0; m_active
= 0 >}
3398 | 108 when ctrl -> (* ctrl-l *)
3399 let first = m_active
- (fstate.maxrows
/ 2) in
3400 G.postRedisplay "outline ctrl-l";
3401 coe {< m_first
= first >}
3403 | 0xff9f | 0xffff -> (* delete *)
3404 source#remove m_active
;
3405 G.postRedisplay "outline delete";
3406 let active = max
0 (m_active
-1) in
3407 coe {< m_first
= firstof m_first
active;
3408 m_active
= active >}
3410 | 0xff52 -> navigate ~
-1 (* up *)
3411 | 0xff54 -> navigate 1 (* down *)
3412 | 0xff55 -> (* prior *)
3413 navigate ~
-(fstate.maxrows
)
3414 | 0xff56 -> (* next *)
3415 navigate fstate.maxrows
3417 | 0xff53 -> (* [ctrl-]right *)
3421 G.postRedisplay "outline ctrl right";
3422 {< m_pan
= m_pan
+ 1 >}
3424 else self#updownlevel
1
3428 | 0xff51 -> (* [ctrl-]left *)
3432 G.postRedisplay "outline ctrl left";
3433 {< m_pan
= m_pan
- 1 >}
3435 else self#updownlevel ~
-1
3439 | 0xff50 -> (* home *)
3440 G.postRedisplay "outline home";
3441 coe {< m_first
= 0; m_active
= 0 >}
3443 | 0xff57 -> (* end *)
3444 let active = source#getitemcount
- 1 in
3445 let first = max
0 (active - fstate.maxrows
) in
3446 G.postRedisplay "outline end";
3447 coe {< m_active
= active; m_first
= first >}
3449 | _ -> super#
key key mask
3452 let outlinesource usebookmarks
=
3455 inherit lvsourcebase
3456 val mutable m_items
= empty
3457 val mutable m_orig_items
= empty
3458 val mutable m_prev_items
= empty
3459 val mutable m_narrow_pattern
= ""
3460 val mutable m_hadremovals
= false
3462 method getitemcount
=
3463 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3466 if n == Array.length m_items
&& m_hadremovals
3468 ("[Confirm removal]", 0)
3470 let s, n, _ = m_items
.(n) in
3473 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3474 ignore
(uioh
, first, qsearch);
3475 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3477 if String.length m_narrow_pattern
= 0
3483 if not
confrimremoval
3485 let _, _, anchor = m_items
.(active) in
3490 state.bookmarks
<- Array.to_list m_items
;
3491 m_orig_items
<- m_items
;
3494 else m_items
<- items;
3498 method hasaction
_ = true
3501 if Array.length m_items
!= Array.length m_orig_items
3502 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3505 method narrow
pattern =
3506 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3510 let rec loop accu n =
3513 m_narrow_pattern
<- pattern;
3514 m_items
<- Array.of_list
accu
3517 let (s, _, _) as o = m_items
.(n) in
3519 if (try ignore
(Str.search_forward
re s 0); true
3520 with Not_found
-> false)
3526 loop [] (Array.length m_items
- 1)
3531 then Array.of_list
state.bookmarks
3534 m_items
<- m_orig_items
3539 if m
>= 0 && m
< Array.length m_items
3541 m_hadremovals
<- true;
3542 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3543 let n = if n >= m
then n+1 else n in
3548 method reset
anchor items =
3549 m_hadremovals
<- false;
3550 if m_orig_items
== empty || m_prev_items
!= items
3552 m_orig_items
<- items;
3553 if String.length m_narrow_pattern
= 0
3554 then m_items
<- items;
3556 m_prev_items
<- items;
3557 let rely = getanchory anchor in
3559 let rec loop n best bestd
=
3560 if n = Array.length m_items
3563 let (_, _, anchor) = m_items
.(n) in
3564 let orely = getanchory anchor in
3565 let d = abs
(orely - rely) in
3568 else loop (n+1) best bestd
3573 m_first
<- firstof m_first
active
3577 let enterselector usebookmarks
=
3578 let source = outlinesource usebookmarks
in
3582 then Array.of_list
state.bookmarks
3585 if Array.length
outlines = 0
3587 showtext ' ' errmsg
;
3590 state.text <- source#greetmsg
;
3591 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3592 let anchor = getanchor () in
3593 source#reset
anchor outlines;
3594 state.uioh
<- coe (new outlinelistview ~
source);
3595 G.postRedisplay "enter selector";
3599 let enteroutlinemode =
3600 let f = enterselector false in
3601 fun ()-> f "Document has no outline";
3604 let enterbookmarkmode =
3605 let f = enterselector true in
3606 fun () -> f "Document has no bookmarks (yet)";
3609 let color_of_string s =
3610 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3611 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3615 let color_to_string (r
, g
, b) =
3616 let r = truncate
(r *. 256.0)
3617 and g
= truncate
(g
*. 256.0)
3618 and b = truncate
(b *. 256.0) in
3619 Printf.sprintf
"%d/%d/%d" r g
b
3622 let irect_of_string s =
3623 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3626 let irect_to_string (x0,y0,x1,y1) =
3627 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3630 let makecheckers () =
3631 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3633 converted by Issac Trotts. July 25, 2002 *)
3634 let image_height = 64
3635 and image_width
= 64 in
3639 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3641 for i
= 0 to image_width
- 1 do
3642 for j
= 0 to image_height - 1 do
3643 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3644 (if (i
land 8 ) lxor (j
land 8) = 0
3645 then [|255;255;255|] else [|200;200;200|])
3650 let image = make_image () in
3651 let id = GlTex.gen_texture
() in
3652 GlTex.bind_texture `texture_2d
id;
3653 GlPix.store
(`unpack_alignment
1);
3654 GlTex.image2d
image;
3655 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3658 `mag_filter `nearest
;
3659 `min_filter `nearest
];
3663 let setcheckers enabled
=
3664 match state.texid
with
3666 if enabled
then state.texid
<- Some
(makecheckers ())
3671 GlTex.delete_texture texid
;
3672 state.texid
<- None
;
3676 let int_of_string_with_suffix s =
3677 let l = String.length
s in
3681 let suffix = Char.lowercase
s.[l-1] in
3683 | 'k'
-> String.sub
s 0 (l-1), 10
3684 | 'm'
-> String.sub
s 0 (l-1), 20
3685 | 'g'
-> String.sub
s 0 (l-1), 30
3689 let n = int_of_string
s1 in
3690 let m = n lsl shift
in
3692 then raise
(Failure
"value too large")
3696 let string_with_suffix_of_int n =
3704 if n land ((1 lsl 20) - 1) = 0
3707 if n land ((1 lsl 10) - 1) = 0
3714 let h = n mod 1000 in
3717 then string_of_int
h ^
s
3719 let s = Printf.sprintf
"_%03d%s" h s in
3726 let defghyllscroll = (40, 8, 32);;
3727 let ghyllscroll_of_string s =
3728 let (n, a, b) as nab
=
3731 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3733 if n <= a || n <= b || a >= b
3734 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3738 let ghyllscroll_to_string ((n, a, b) as nab
) =
3739 if nab
= defghyllscroll
3741 else Printf.sprintf
"%d,%d,%d" n a b;
3744 let describe_location () =
3746 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3748 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3749 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3753 else (100. *. (float state.y /. float maxy))
3757 Printf.sprintf
"page %d of %d [%.2f%%]"
3758 (fn+1) state.pagecount
percent
3761 "pages %d-%d of %d [%.2f%%]"
3762 (fn+1) (ln
+1) state.pagecount
percent
3766 let btos b = if b then "\xe2\x88\x9a" else "" in
3767 let showextended = ref false in
3768 let leave mode = function
3769 | Confirm
-> state.mode <- mode
3770 | Cancel
-> state.mode <- mode in
3773 val mutable m_first_time
= true
3774 val mutable m_l
= []
3775 val mutable m_a
= [||]
3776 val mutable m_prev_uioh
= nouioh
3777 val mutable m_prev_mode
= View
3779 inherit lvsourcebase
3781 method reset prev_mode prev_uioh
=
3782 m_a
<- Array.of_list
(List.rev m_l
);
3784 m_prev_mode
<- prev_mode
;
3785 m_prev_uioh
<- prev_uioh
;
3789 if n >= Array.length m_a
3793 | _, _, _, Action
_ -> m_active
<- n
3797 m_first_time
<- false;
3800 method int name get
set =
3802 (name
, `
int get
, 1, Action
(
3805 try set (int_of_string
s)
3807 state.text <- Printf.sprintf
"bad integer `%s': %s"
3808 s (Printexc.to_string exn
)
3811 let te = name ^
": ", "", None
, intentry, ondone in
3812 state.mode <- Textentry
(te, leave m_prev_mode
);
3816 method int_with_suffix name get
set =
3818 (name
, `intws get
, 1, Action
(
3821 try set (int_of_string_with_suffix s)
3823 state.text <- Printf.sprintf
"bad integer `%s': %s"
3824 s (Printexc.to_string exn
)
3828 name ^
": ", "", None
, intentry_with_suffix, ondone
3830 state.mode <- Textentry
(te, leave m_prev_mode
);
3834 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3836 (name
, `
bool (btos, get
), offset
, Action
(
3843 method color name get
set =
3845 (name
, `color get
, 1, Action
(
3847 let invalid = (nan
, nan
, nan
) in
3850 try color_of_string s
3852 state.text <- Printf.sprintf
"bad color `%s': %s"
3853 s (Printexc.to_string exn
);
3859 let te = name ^
": ", "", None
, textentry, ondone in
3860 state.text <- color_to_string (get
());
3861 state.mode <- Textentry
(te, leave m_prev_mode
);
3865 method string name get
set =
3867 (name
, `
string get
, 1, Action
(
3869 let ondone s = set s in
3870 let te = name ^
": ", "", None
, textentry, ondone in
3871 state.mode <- Textentry
(te, leave m_prev_mode
);
3875 method colorspace name get
set =
3877 (name
, `
string get
, 1, Action
(
3880 let vals = [| "rgb"; "bgr"; "gray" |] in
3882 inherit lvsourcebase
3885 m_active
<- int_of_colorspace conf.colorspace
;
3888 method getitemcount
= Array.length
vals
3889 method getitem
n = (vals.(n), 0)
3890 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3891 ignore
(uioh
, first, pan
, qsearch);
3892 if not cancel
then set active;
3894 method hasaction
_ = true
3898 let modehash = findkeyhash conf "info" in
3899 coe (new listview ~
source ~trusted
:true ~
modehash)
3902 method caption
s offset
=
3903 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3905 method caption2
s f offset
=
3906 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3908 method getitemcount
= Array.length m_a
3911 let tostr = function
3912 | `
int f -> string_of_int
(f ())
3913 | `intws
f -> string_with_suffix_of_int (f ())
3915 | `color
f -> color_to_string (f ())
3916 | `
bool (btos, f) -> btos (f ())
3919 let name, t
, offset
, _ = m_a
.(n) in
3920 ((let s = tostr t
in
3921 if String.length
s > 0
3922 then Printf.sprintf
"%s\t%s" name s
3926 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3930 m_qsearch
<- qsearch;
3932 match m_a
.(active) with
3933 | _, _, _, Action
f -> f uioh
3945 method hasaction
n =
3947 | _, _, _, Action
_ -> true
3951 let rec fillsrc prevmode prevuioh
=
3952 let sep () = src#caption
"" 0 in
3953 let colorp name get
set =
3955 (fun () -> color_to_string (get
()))
3958 let c = color_of_string v in
3961 state.text <- Printf.sprintf
"bad color `%s': %s"
3962 v (Printexc.to_string exn
);
3965 let oldmode = state.mode in
3966 let birdseye = isbirdseye state.mode in
3968 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3970 src#
bool "presentation mode"
3971 (fun () -> conf.presentation)
3973 conf.presentation <- v;
3974 state.anchor <- getanchor ();
3977 src#
bool "ignore case in searches"
3978 (fun () -> conf.icase
)
3979 (fun v -> conf.icase
<- v);
3982 (fun () -> conf.preload)
3983 (fun v -> conf.preload <- v);
3985 src#
bool "highlight links"
3986 (fun () -> conf.hlinks
)
3987 (fun v -> conf.hlinks
<- v);
3989 src#
bool "under info"
3990 (fun () -> conf.underinfo
)
3991 (fun v -> conf.underinfo
<- v);
3993 src#
bool "persistent bookmarks"
3994 (fun () -> conf.savebmarks
)
3995 (fun v -> conf.savebmarks
<- v);
3997 src#
bool "proportional display"
3998 (fun () -> conf.proportional
)
3999 (fun v -> reqlayout conf.angle
v);
4001 src#
bool "trim margins"
4002 (fun () -> conf.trimmargins
)
4003 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4005 src#
bool "persistent location"
4006 (fun () -> conf.jumpback
)
4007 (fun v -> conf.jumpback
<- v);
4010 src#
int "inter-page space"
4011 (fun () -> conf.interpagespace)
4013 conf.interpagespace <- n;
4015 match state.layout with
4020 state.maxy <- calcheight ();
4021 let y = getpagey pageno in
4026 (fun () -> conf.pagebias
)
4027 (fun v -> conf.pagebias
<- v);
4029 src#
int "scroll step"
4030 (fun () -> conf.scrollstep
)
4031 (fun n -> conf.scrollstep
<- n);
4033 src#
int "auto scroll step"
4035 match state.autoscroll
with
4037 | _ -> conf.autoscrollstep
)
4039 if state.autoscroll
<> None
4040 then state.autoscroll
<- Some
n;
4041 conf.autoscrollstep
<- n);
4044 (fun () -> truncate
(conf.zoom *. 100.))
4045 (fun v -> setzoom ((float v) /. 100.));
4048 (fun () -> conf.angle
)
4049 (fun v -> reqlayout v conf.proportional
);
4051 src#
int "scroll bar width"
4052 (fun () -> state.scrollw
)
4056 reshape conf.winw
conf.winh
;
4059 src#
int "scroll handle height"
4060 (fun () -> conf.scrollh
)
4061 (fun v -> conf.scrollh
<- v;);
4063 src#
int "thumbnail width"
4064 (fun () -> conf.thumbw
)
4066 conf.thumbw
<- min
4096 v;
4069 leavebirdseye beye
false;
4074 let mode = state.mode in
4075 src#
string "columns"
4077 match conf.columns
with
4079 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4080 | Csplit
(count
, _) -> "-" ^ string_of_int count
4083 let n, a, b = multicolumns_of_string v in
4084 setcolumns mode n a b);
4087 src#caption
"Presentation mode" 0;
4088 src#
bool "scrollbar visible"
4089 (fun () -> conf.scrollbarinpm
)
4091 if v != conf.scrollbarinpm
4093 conf.scrollbarinpm
<- v;
4094 if conf.presentation
4096 state.scrollw
<- if v then conf.scrollbw
else 0;
4097 reshape conf.winw
conf.winh
;
4103 src#caption
"Pixmap cache" 0;
4104 src#int_with_suffix
"size (advisory)"
4105 (fun () -> conf.memlimit
)
4106 (fun v -> conf.memlimit
<- v);
4109 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4110 (string_with_suffix_of_int state.memused
)
4111 (Hashtbl.length
state.tilemap
)) 1;
4114 src#caption
"Layout" 0;
4115 src#caption2
"Dimension"
4117 Printf.sprintf
"%dx%d (virtual %dx%d)"
4123 src#caption2
"Position" (fun () ->
4124 Printf.sprintf
"%dx%d" state.x state.y
4127 src#caption2
"Visible" (fun () -> describe_location ()) 1
4131 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4132 "Save these parameters as global defaults at exit"
4133 (fun () -> conf.bedefault
)
4134 (fun v -> conf.bedefault
<- v)
4138 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4139 src#
bool ~offset
:0 ~
btos "Extended parameters"
4140 (fun () -> !showextended)
4141 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4145 (fun () -> conf.checkers
)
4146 (fun v -> conf.checkers
<- v; setcheckers v);
4147 src#
bool "update cursor"
4148 (fun () -> conf.updatecurs
)
4149 (fun v -> conf.updatecurs
<- v);
4151 (fun () -> conf.verbose
)
4152 (fun v -> conf.verbose
<- v);
4153 src#
bool "invert colors"
4154 (fun () -> conf.invert
)
4155 (fun v -> conf.invert
<- v);
4157 (fun () -> conf.maxhfit
)
4158 (fun v -> conf.maxhfit
<- v);
4159 src#
bool "redirect stderr"
4160 (fun () -> conf.redirectstderr)
4161 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4162 src#
string "uri launcher"
4163 (fun () -> conf.urilauncher
)
4164 (fun v -> conf.urilauncher
<- v);
4165 src#
string "path launcher"
4166 (fun () -> conf.pathlauncher
)
4167 (fun v -> conf.pathlauncher
<- v);
4168 src#
string "tile size"
4169 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4172 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4173 conf.tileh
<- max
64 w;
4174 conf.tilew
<- max
64 h;
4177 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4178 v (Printexc.to_string exn
));
4179 src#
int "texture count"
4180 (fun () -> conf.texcount
)
4183 then conf.texcount
<- v
4184 else showtext '
!'
" Failed to set texture count please retry later"
4186 src#
int "slice height"
4187 (fun () -> conf.sliceheight
)
4189 conf.sliceheight
<- v;
4190 wcmd "sliceh %d" conf.sliceheight
;
4192 src#
int "anti-aliasing level"
4193 (fun () -> conf.aalevel
)
4195 conf.aalevel
<- bound v 0 8;
4196 state.anchor <- getanchor ();
4197 opendoc state.path
state.password
;
4199 src#
int "ui font size"
4200 (fun () -> fstate.fontsize
)
4201 (fun v -> setfontsize (bound v 5 100));
4202 colorp "background color"
4203 (fun () -> conf.bgcolor
)
4204 (fun v -> conf.bgcolor
<- v);
4205 src#
bool "crop hack"
4206 (fun () -> conf.crophack
)
4207 (fun v -> conf.crophack
<- v);
4208 src#
string "trim fuzz"
4209 (fun () -> irect_to_string conf.trimfuzz
)
4212 conf.trimfuzz
<- irect_of_string v;
4214 then settrim true conf.trimfuzz
;
4216 state.text <- Printf.sprintf
"bad irect `%s': %s"
4217 v (Printexc.to_string exn
)
4219 src#
string "throttle"
4221 match conf.maxwait
with
4222 | None
-> "show place holder if page is not ready"
4225 then "wait for page to fully render"
4227 "wait " ^ string_of_float
time
4228 ^
" seconds before showing placeholder"
4232 let f = float_of_string
v in
4234 then conf.maxwait
<- None
4235 else conf.maxwait
<- Some
f
4237 state.text <- Printf.sprintf
"bad time `%s': %s"
4238 v (Printexc.to_string exn
)
4240 src#
string "ghyll scroll"
4242 match conf.ghyllscroll
with
4244 | Some nab
-> ghyllscroll_to_string nab
4249 if String.length
v = 0
4251 else Some
(ghyllscroll_of_string v)
4253 conf.ghyllscroll
<- gs
4255 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4256 v (Printexc.to_string exn
)
4258 src#
string "selection command"
4259 (fun () -> conf.selcmd
)
4260 (fun v -> conf.selcmd
<- v);
4261 src#colorspace
"color space"
4262 (fun () -> colorspace_to_string conf.colorspace
)
4264 conf.colorspace
<- colorspace_of_int v;
4271 src#caption
"Document" 0;
4272 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4273 src#caption2
"Pages"
4274 (fun () -> string_of_int
state.pagecount
) 1;
4275 src#caption2
"Dimensions"
4276 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4280 src#caption
"Trimmed margins" 0;
4281 src#caption2
"Dimensions"
4282 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4285 src#reset prevmode prevuioh
;
4289 let prevmode = state.mode
4290 and prevuioh
= state.uioh in
4291 fillsrc prevmode prevuioh
;
4292 let source = (src :> lvsource
) in
4293 let modehash = findkeyhash conf "info" in
4294 state.uioh <- coe (object (self)
4295 inherit listview ~
source ~trusted
:true ~
modehash as super
4296 val mutable m_prevmemused
= 0
4297 method infochanged
= function
4299 if m_prevmemused
!= state.memused
4301 m_prevmemused
<- state.memused
;
4302 G.postRedisplay "memusedchanged";
4304 | Pdim
-> G.postRedisplay "pdimchanged"
4305 | Docinfo
-> fillsrc prevmode prevuioh
4307 method key key mask
=
4308 if not
(Wsi.withctrl mask
)
4311 | 0xff51 -> coe (self#updownlevel ~
-1)
4312 | 0xff53 -> coe (self#updownlevel
1)
4313 | _ -> super#
key key mask
4314 else super#
key key mask
4316 G.postRedisplay "info";
4322 inherit lvsourcebase
4323 method getitemcount
= Array.length
state.help
4325 let s, n, _ = state.help
.(n) in
4328 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4332 m_qsearch
<- qsearch;
4333 match state.help
.(active) with
4334 | _, _, Action
f -> Some
(f uioh)
4344 method hasaction
n =
4345 match state.help
.(n) with
4346 | _, _, Action
_ -> true
4353 let modehash = findkeyhash conf "help" in
4354 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4355 G.postRedisplay "help";
4360 let re = Str.regexp
"[\r\n]" in
4362 inherit lvsourcebase
4363 val mutable m_items
= [||]
4365 method getitemcount
= 1 + Array.length m_items
4370 else m_items
.(n-1), 0
4372 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4377 then Buffer.clear
state.errmsgs
;
4378 m_qsearch
<- qsearch;
4385 method hasaction
n =
4389 state.newerrmsgs
<- false;
4390 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4391 m_items
<- Array.of_list
l
4399 let source = (msgsource :> lvsource
) in
4400 let modehash = findkeyhash conf "listview" in
4401 state.uioh <- coe (object
4402 inherit listview ~
source ~trusted
:false ~
modehash as super
4405 then msgsource#reset
;
4408 G.postRedisplay "msgs";
4411 let quickbookmark ?title
() =
4412 match state.layout with
4418 let sec = Unix.gettimeofday
() in
4419 let tm = Unix.localtime
sec in
4420 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4424 (tm.Unix.tm_year
+ 1900)
4427 | Some
title -> title
4430 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4435 state.fullscreen
<- None
;
4439 let setautoscrollspeed step goingdown
=
4440 let incr = max
1 ((abs step
) / 2) in
4441 let incr = if goingdown
then incr else -incr in
4442 let astep = step
+ incr in
4443 state.autoscroll
<- Some
astep;
4446 let gotounder = function
4447 | Ulinkgoto
(pageno, top) ->
4451 gotopage1 pageno top;
4457 | Uremote
(filename
, pageno) ->
4459 if Sys.file_exists filename
4462 let dir = Filename.dirname
state.path in
4463 let path = Filename.concat
dir filename
in
4464 if Sys.file_exists
path
4468 if String.length
path > 0
4470 let anchor = getanchor () in
4471 let ranchor = state.path, state.password
, anchor in
4472 state.anchor <- (pageno, 0.0);
4473 state.ranchors
<- ranchor :: state.ranchors
;
4476 else showtext '
!'
("Could not find " ^ filename
)
4478 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4482 match conf.columns
with
4484 | _ -> conf.zoom > 1.0
4487 let viewkeyboard key mask
=
4489 let mode = state.mode in
4490 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4493 G.postRedisplay "view:enttext"
4495 let ctrl = Wsi.withctrl mask
in
4500 | 0xff63 -> (* insert *)
4501 if conf.angle
mod 360 = 0
4503 state.mode <- LinkNav
(Ltgendir
0);
4506 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4508 | 0xff1b | 113 -> (* escape / q *)
4509 begin match state.mstate
with
4511 state.mstate
<- Mnone
;
4512 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4513 G.postRedisplay "kill zoom rect";
4515 match state.ranchors
with
4517 | (path, password
, anchor) :: rest
->
4518 state.ranchors
<- rest
;
4519 state.anchor <- anchor;
4520 opendoc path password
4523 | 0xff08 -> (* backspace *)
4524 let y = getnav ~
-1 in
4525 gotoy_and_clear_text y
4533 G.postRedisplay "dehighlight";
4535 | 47 | 63 -> (* / ? *)
4536 let ondone isforw
s =
4537 cbput state.hists
.pat
s;
4538 state.searchpattern
<- s;
4541 let s = String.create
1 in
4542 s.[0] <- Char.chr
key;
4543 enttext (s, "", Some
(onhist state.hists
.pat
),
4544 textentry, ondone (key = 47))
4546 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4547 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4548 setzoom (conf.zoom +. incr)
4550 | 43 | 0xffab -> (* + *)
4553 try int_of_string
s with exc
->
4554 state.text <- Printf.sprintf
"bad integer `%s': %s"
4555 s (Printexc.to_string exc
);
4561 state.text <- "page bias is now " ^ string_of_int
n;
4564 enttext ("page bias: ", "", None
, intentry, ondone)
4566 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4567 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4568 setzoom (max
0.01 (conf.zoom -. decr))
4570 | 45 | 0xffad -> (* - *)
4571 let ondone msg
= state.text <- msg
in
4573 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4574 optentry state.mode, ondone
4577 | 48 when ctrl -> (* ctrl-0 *)
4580 | 49 when ctrl -> (* 1 *)
4581 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4585 | 0xffc6 -> (* f9 *)
4588 | 57 when ctrl -> (* ctrl-9 *)
4591 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4592 when not
ctrl -> (* 0..9 *)
4595 try int_of_string
s with exc
->
4596 state.text <- Printf.sprintf
"bad integer `%s': %s"
4597 s (Printexc.to_string exc
);
4603 cbput state.hists
.pag
(string_of_int
n);
4604 gotopage1 (n + conf.pagebias
- 1) 0;
4607 let pageentry text key =
4608 match Char.unsafe_chr
key with
4609 | 'g'
-> TEdone
text
4610 | _ -> intentry text key
4612 let text = "x" in text.[0] <- Char.chr
key;
4613 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4616 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4617 reshape conf.winw
conf.winh
;
4620 conf.hlinks
<- not
conf.hlinks
;
4621 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4622 G.postRedisplay "toggle highlightlinks";
4625 state.glinks
<- true;
4626 let a = Char.code '
a'
and z
= Char.code 'z'
in
4629 let rec loop pos
n = if pos
= String.length
s then n else
4630 let m = Char.code
s.[pos
] - a in
4631 loop (pos
+1) (n*(z
-a+1) + m)
4636 let rec loop n = function
4639 match getopaque l.pageno with
4640 | None
-> loop n rest
4642 let m = getlinkcount opaque
in
4645 let under = getlink opaque
n in
4649 else loop (n-m) rest
4651 loop n state.layout;
4654 let onkey text key =
4655 if (key >= a && key <= z
)
4657 let c = Char.unsafe_chr
key in
4658 let text = addchar text c in
4663 let mode = state.mode in
4664 state.mode <- Textentry
(
4665 (":", "", Some
(onhist state.hists
.pag
), onkey, ondone),
4667 state.glinks
<- false;
4671 G.postRedisplay "view:enttext"
4674 begin match state.autoscroll
with
4676 conf.autoscrollstep
<- step
;
4677 state.autoscroll
<- None
4679 if conf.autoscrollstep
= 0
4680 then state.autoscroll
<- Some
1
4681 else state.autoscroll
<- Some
conf.autoscrollstep
4684 | 112 when ctrl -> (* ctrl-p *)
4688 conf.presentation <- not
conf.presentation;
4689 if conf.presentation
4691 if not
conf.scrollbarinpm
4692 then state.scrollw
<- 0;
4695 state.scrollw
<- conf.scrollbw
;
4697 showtext ' '
("presentation mode " ^
4698 if conf.presentation then "on" else "off");
4699 state.anchor <- getanchor ();
4703 begin match state.fullscreen
with
4705 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4708 state.fullscreen
<- None
;
4713 gotoy_and_clear_text 0
4716 gotopage1 (state.pagecount
- 1) 0
4718 | 112 | 78 -> (* p|N *)
4719 search state.searchpattern
false
4721 | 110 | 0xffc0 -> (* n|F3 *)
4722 search state.searchpattern
true
4725 begin match state.layout with
4728 gotoy_and_clear_text (getpagey l.pageno)
4732 begin match List.rev
state.layout with
4735 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4736 gotoy_and_clear_text (getpagey pageno)
4739 | 0xff9f | 0xffff -> (* delete *)
4740 begin match state.layout with
4743 let pageno = max
0 (l.pageno-1) in
4744 gotoy_and_clear_text (getpagey pageno)
4748 showtext ' '
(describe_location ());
4751 begin match state.layout with
4754 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4759 enterbookmarkmode ()
4761 | 104 | 0xffbe -> (* h|F1 *)
4767 | 101 when conf.redirectstderr -> (* e *)
4772 match state.layout with
4775 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4779 enttext ("bookmark: ", "", None
, textentry, ondone)
4783 showtext ' '
"Quick bookmark added";
4786 begin match state.layout with
4788 let rect = getpdimrect
l.pagedimno
in
4792 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4793 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4795 (truncate
(rect.(1) -. rect.(0)),
4796 truncate
(rect.(3) -. rect.(0)))
4798 let w = truncate
((float w)*.conf.zoom)
4799 and h = truncate
((float h)*.conf.zoom) in
4802 state.anchor <- getanchor ();
4803 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4805 G.postRedisplay "z";
4810 | 50 when ctrl -> (* ctrl-2 *)
4811 let maxw = getmaxw
() in
4813 then setzoom (maxw /. float conf.winw
)
4815 | 60 | 62 -> (* < > *)
4816 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
4818 | 91 | 93 -> (* [ ] *)
4820 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
4822 G.postRedisplay "brightness";
4824 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
4825 setzoom state.prevzoom
4827 | 107 | 0xff52 -> (* k up *)
4828 begin match state.autoscroll
with
4830 begin match state.mode with
4831 | Birdseye beye
-> upbirdseye 1 beye
4834 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
4835 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
4838 setautoscrollspeed n false
4841 | 106 | 0xff54 -> (* j down *)
4842 begin match state.autoscroll
with
4844 begin match state.mode with
4845 | Birdseye beye
-> downbirdseye 1 beye
4848 then gotoy_and_clear_text (clamp (conf.winh
/2))
4849 else gotoy_and_clear_text (clamp conf.scrollstep
)
4852 setautoscrollspeed n true
4855 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
4863 let dx = if key = 0xff51 then dx else -dx in
4864 state.x <- state.x + dx;
4865 gotoy_and_clear_text state.y
4868 G.postRedisplay "lef/right"
4871 | 0xff55 -> (* prior *)
4875 match state.layout with
4877 | l :: _ -> state.y - l.pagey
4883 | 0xff56 -> (* next *)
4887 match List.rev
state.layout with
4889 | l :: _ -> getpagey l.pageno
4895 | 0xff50 -> gotoghyll 0
4896 | 0xff57 -> gotoghyll (clamp state.maxy)
4897 | 0xff53 when Wsi.withalt mask
->
4898 gotoghyll (getnav ~
-1)
4899 | 0xff51 when Wsi.withalt mask
->
4900 gotoghyll (getnav 1)
4903 state.anchor <- getanchor ();
4904 opendoc state.path state.password
4906 | 118 when conf.debug
-> (* v *)
4909 match getopaque l.pageno with
4912 let x0, y0, x1, y1 = pagebbox opaque
in
4913 let a,b = float x0, float y0 in
4914 let c,d = float x1, float y0 in
4915 let e,f = float x1, float y1 in
4916 let h,j
= float x0, float y1 in
4917 let rect = (a,b,c,d,e,f,h,j
) in
4919 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4921 G.postRedisplay "v";
4924 vlog "huh? %s" (Wsi.keyname
key)
4927 let linknavkeyboard key mask
linknav =
4928 let getpage pageno =
4929 let rec loop = function
4931 | l :: _ when l.pageno = pageno -> Some
l
4932 | _ :: rest
-> loop rest
4933 in loop state.layout
4935 let doexact (pageno, n) =
4936 match getopaque pageno, getpage pageno with
4937 | Some opaque
, Some
l ->
4940 let under = getlink opaque
n in
4941 G.postRedisplay "link gotounder";
4947 | 0xff50 -> (* home *)
4948 Some
(findlink opaque LDfirst
), -1
4950 | 0xff57 -> (* end *)
4951 Some
(findlink opaque LDlast
), 1
4953 | 0xff51 -> (* left *)
4954 Some
(findlink opaque
(LDleft
n)), -1
4956 | 0xff53 -> (* right *)
4957 Some
(findlink opaque
(LDright
n)), 1
4959 | 0xff52 -> (* up *)
4960 Some
(findlink opaque
(LDup
n)), -1
4962 | 0xff54 -> (* down *)
4963 Some
(findlink opaque
(LDdown
n)), 1
4968 begin match findpwl
l.pageno dir with
4972 state.mode <- LinkNav
(Ltgendir
dir);
4973 let y, h = getpageyh pageno in
4976 then y + h - conf.winh
4981 begin match getopaque pageno, getpage pageno with
4982 | Some opaque
, Some
_ ->
4984 let ld = if dir > 0 then LDfirst
else LDlast
in
4987 begin match link with
4989 showlinktype (getlink opaque
m);
4990 state.mode <- LinkNav
(Ltexact
(pageno, m));
4991 G.postRedisplay "linknav jpage";
4998 begin match opt with
4999 | Some Lnotfound
-> pwl l dir;
5000 | Some
(Lfound
m) ->
5004 let _, y0, _, y1 = getlinkrect opaque
m in
5006 then gotopage1 l.pageno y0
5008 let d = fstate.fontsize
+ 1 in
5009 if y1 - l.pagey > l.pagevh - d
5010 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5011 else G.postRedisplay "linknav";
5013 showlinktype (getlink opaque
m);
5014 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5017 | None
-> viewkeyboard key mask
5019 | _ -> viewkeyboard key mask
5024 G.postRedisplay "leave linknav"
5028 | Ltgendir
_ -> viewkeyboard key mask
5029 | Ltexact exact
-> doexact exact
5032 let keyboard key mask
=
5033 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5034 then wcmd "interrupt"
5035 else state.uioh <- state.uioh#
key key mask
5038 let birdseyekeyboard key mask
5039 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5041 match conf.columns
with
5043 | Cmulti
((c, _, _), _) -> c
5044 | Csplit
_ -> failwith
"bird's eye split mode"
5047 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5048 let y, h = getpageyh pageno in
5049 let top = (conf.winh
- h) / 2 in
5050 gotoy (max
0 (y - top))
5051 | 0xff0d -> leavebirdseye beye
false
5052 | 0xff1b -> leavebirdseye beye
true (* escape *)
5053 | 0xff52 -> upbirdseye incr beye
(* prior *)
5054 | 0xff54 -> downbirdseye incr beye
(* next *)
5055 | 0xff51 -> upbirdseye 1 beye
(* up *)
5056 | 0xff53 -> downbirdseye 1 beye
(* down *)
5059 begin match state.layout with
5063 state.mode <- Birdseye
(
5064 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5066 gotopage1 l.pageno 0;
5069 let layout = layout (state.y-conf.winh
) conf.winh
in
5071 | [] -> gotoy (clamp (-conf.winh
))
5073 state.mode <- Birdseye
(
5074 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5076 gotopage1 l.pageno 0
5079 | [] -> gotoy (clamp (-conf.winh
))
5083 begin match List.rev
state.layout with
5085 let layout = layout (state.y + conf.winh
) conf.winh
in
5086 begin match layout with
5088 let incr = l.pageh
- l.pagevh in
5093 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5095 G.postRedisplay "birdseye pagedown";
5097 else gotoy (clamp (incr + conf.interpagespace*2));
5101 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5102 gotopage1 l.pageno 0;
5105 | [] -> gotoy (clamp conf.winh
)
5109 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5113 let pageno = state.pagecount
- 1 in
5114 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5115 if not
(pagevisible state.layout pageno)
5118 match List.rev
state.pdims
with
5120 | (_, _, h, _) :: _ -> h
5122 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5123 else G.postRedisplay "birdseye end";
5124 | _ -> viewkeyboard key mask
5127 let drawpage l linkindexbase
=
5129 match state.mode with
5130 | Textentry
_ -> scalecolor 0.4
5132 | View
-> scalecolor 1.0
5133 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5134 if l.pageno = hooverpageno
5137 if l.pageno = pageno
5143 begin match getopaque l.pageno with
5145 if tileready l l.pagex l.pagey
5147 let x = l.pagedispx - l.pagex
5148 and y = l.pagedispy - l.pagey in
5149 let hlmask = (if conf.hlinks
then 1 else 0)
5150 + (if state.glinks
&& not
(isbirdseye state.mode) then 2 else 0)
5152 postprocess opaque
hlmask x y linkindexbase
;
5159 let scrollindicator () =
5160 let sbw, ph
, sh = state.uioh#
scrollph in
5161 let sbh, pw, sw = state.uioh#scrollpw
in
5163 GlDraw.color (0.64, 0.64, 0.64);
5165 (float (conf.winw
- sbw), 0.)
5166 (float conf.winw
, float conf.winh
)
5169 (0., float (conf.winh
- sbh))
5170 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5172 GlDraw.color (0.0, 0.0, 0.0);
5175 (float (conf.winw
- sbw), ph
)
5176 (float conf.winw
, ph
+. sh)
5179 (pw, float (conf.winh
- sbh))
5180 (pw +. sw, float conf.winh
)
5185 match state.mstate
with
5186 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5189 | Msel
((x0, y0), (x1, y1)) ->
5190 let rec loop = function
5192 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5193 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5194 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5195 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5197 match getopaque l.pageno with
5199 let x0, y0 = pagetranslatepoint l x0 y0 in
5200 let x1, y1 = pagetranslatepoint l x1 y1 in
5201 seltext opaque
(x0, y0, x1, y1);
5209 let showrects rects
=
5211 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5212 GlDraw.polygon_mode `both `fill
;
5213 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5215 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5217 if l.pageno = pageno
5219 let dx = float (l.pagedispx - l.pagex) in
5220 let dy = float (l.pagedispy - l.pagey) in
5221 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5222 GlDraw.begins `quads
;
5224 GlDraw.vertex2
(x0+.dx, y0+.dy);
5225 GlDraw.vertex2
(x1+.dx, y1+.dy);
5226 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5227 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5238 GlClear.color (scalecolor2 conf.bgcolor
);
5239 GlClear.clear
[`
color];
5240 let rec loop linkindexbase
= function
5242 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5243 loop linkindexbase rest
5246 loop 0 state.layout;
5248 match state.mode with
5249 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5250 begin match getopaque pageno with
5252 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5259 | None
-> state.rects
5266 begin match state.mstate
with
5267 | Mzoomrect
((x0, y0), (x1, y1)) ->
5269 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5270 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5271 GlDraw.rect (float x0, float y0)
5272 (float x1, float y1);
5281 let zoomrect x y x1 y1 =
5284 and y0 = min
y y1 in
5285 gotoy (state.y + y0);
5286 state.anchor <- getanchor ();
5287 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5289 if state.w < conf.winw
- state.scrollw
5290 then (conf.winw
- state.scrollw
- state.w) / 2
5293 state.x <- (state.x + margin) - x0;
5295 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5296 state.mstate
<- Mnone
;
5300 let winw = conf.winw - state.scrollw
- 1 in
5301 let s = float x /. float winw in
5302 let destx = truncate
(float (state.w + winw) *. s) in
5303 state.x <- winw - destx;
5304 gotoy_and_clear_text state.y;
5305 state.mstate
<- Mscrollx
;
5309 let s = float y /. float conf.winh
in
5310 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5311 gotoy_and_clear_text desty;
5312 state.mstate
<- Mscrolly
;
5315 let viewmouse button down
x y mask
=
5317 | n when (n == 4 || n == 5) && not down
->
5318 if Wsi.withctrl mask
5320 match state.mstate
with
5321 | Mzoom
(oldn
, i
) ->
5329 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5331 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5333 let zoom = conf.zoom -. incr in
5335 state.mstate
<- Mzoom
(n, 0);
5337 state.mstate
<- Mzoom
(n, i
+1);
5339 else state.mstate
<- Mzoom
(n, 0)
5341 | _ -> state.mstate
<- Mzoom
(n, 0)
5344 match state.autoscroll
with
5345 | Some step
-> setautoscrollspeed step
(n=4)
5349 then -conf.scrollstep
5350 else conf.scrollstep
5352 let incr = incr * 2 in
5353 let y = clamp incr in
5354 gotoy_and_clear_text y
5357 | 1 when Wsi.withctrl mask
->
5360 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5361 state.mstate
<- Mpan
(x, y)
5364 state.mstate
<- Mnone
5369 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5371 state.mstate
<- Mzoomrect
(p, p)
5374 match state.mstate
with
5375 | Mzoomrect
((x0, y0), _) ->
5376 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5377 then zoomrect x0 y0 x y
5379 state.mstate
<- Mnone
;
5380 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5381 G.postRedisplay "kill accidental zoom rect";
5384 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5385 state.mstate
<- Mnone
5388 | 1 when x > conf.winw - state.scrollw
->
5391 let _, position, sh = state.uioh#
scrollph in
5392 if y > truncate
position && y < truncate
(position +. sh)
5393 then state.mstate
<- Mscrolly
5396 state.mstate
<- Mnone
5398 | 1 when y > conf.winh
- state.hscrollh ->
5401 let _, position, sw = state.uioh#scrollpw
in
5402 if x > truncate
position && x < truncate
(position +. sw)
5403 then state.mstate
<- Mscrollx
5406 state.mstate
<- Mnone
5409 let dest = if down
then getunder x y else Unone
in
5410 begin match dest with
5414 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5417 | Unone
when down
->
5418 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5419 state.mstate
<- Mpan
(x, y);
5421 | Unone
| Utext
_ ->
5424 if conf.angle
mod 360 = 0
5426 state.mstate
<- Msel
((x, y), (x, y));
5427 G.postRedisplay "mouse select";
5431 match state.mstate
with
5434 | Mzoom
_ | Mscrollx
| Mscrolly
->
5435 state.mstate
<- Mnone
5437 | Mzoomrect
((x0, y0), _) ->
5441 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5442 state.mstate
<- Mnone
5444 | Msel
((_, y0), (_, y1)) ->
5445 let rec loop = function
5448 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5449 || ((y1 >= l.pagedispy
5450 && y1 <= (l.pagedispy + l.pagevh)))
5452 match getopaque l.pageno with
5454 let r, w = Unix.pipe
() in
5455 popen
conf.selcmd
[r, 0; w, -1];
5458 G.postRedisplay "copysel"
5463 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5464 state.mstate
<- Mnone
;
5471 let birdseyemouse button down
x y mask
5472 (conf, leftx
, _, hooverpageno
, anchor) =
5475 let rec loop = function
5478 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5479 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5481 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5487 | _ -> viewmouse button down
x y mask
5490 let mouse button down
x y mask
=
5491 state.uioh <- state.uioh#button button down
x y mask
;
5495 state.uioh <- state.uioh#
motion x y
5499 state.uioh <- state.uioh#
pmotion x y;
5505 method key key mask
=
5506 begin match state.mode with
5507 | Textentry
textentry -> textentrykeyboard key mask
textentry
5508 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5509 | View
-> viewkeyboard key mask
5510 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5514 method button button bstate
x y mask
=
5515 begin match state.mode with
5517 | View
-> viewmouse button bstate
x y mask
5518 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5524 begin match state.mode with
5526 | View
| Birdseye
_ | LinkNav
_ ->
5527 match state.mstate
with
5528 | Mzoom
_ | Mnone
-> ()
5533 state.mstate
<- Mpan
(x, y);
5535 then state.x <- state.x + dx;
5537 gotoy_and_clear_text y
5540 state.mstate
<- Msel
(a, (x, y));
5541 G.postRedisplay "motion select";
5544 let y = min
conf.winh
(max
0 y) in
5548 let x = min
conf.winw (max
0 x) in
5551 | Mzoomrect
(p0
, _) ->
5552 state.mstate
<- Mzoomrect
(p0
, (x, y));
5553 G.postRedisplay "motion zoomrect";
5557 method pmotion x y =
5558 begin match state.mode with
5559 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5560 let rec loop = function
5562 if hooverpageno
!= -1
5564 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5565 G.postRedisplay "pmotion birdseye no hoover";
5568 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5569 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5571 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5572 G.postRedisplay "pmotion birdseye hoover";
5582 match state.mstate
with
5583 | Mnone
-> updateunder x y
5584 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5589 method infochanged
_ = ()
5592 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5593 let p, h = scrollph state.y maxy in
5597 let winw = conf.winw - state.scrollw
- 1 in
5598 let fwinw = float winw in
5600 let sw = fwinw /. float state.w in
5601 let sw = fwinw *. sw in
5602 max
sw (float conf.scrollh
)
5605 let f = state.w+winw in
5606 let r = float (winw-state.x) /. float f in
5607 let p = fwinw *. r in
5611 if position +. sw > fwinw
5612 then fwinw -. position
5615 state.hscrollh, position, sw
5619 match state.mode with
5620 | LinkNav
_ -> "links"
5621 | Textentry
_ -> "textentry"
5622 | Birdseye
_ -> "birdseye"
5625 findkeyhash conf modename
5632 let fontpath = ref "";;
5635 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5638 let l = String.length
s in
5639 let b = Buffer.create
l in
5645 try Sys.getenv
"HOME"
5648 ("Can not determine home directory location: " ^
5649 Printexc.to_string exn
);
5653 let modifier_of_string = function
5654 | "alt" -> Wsi.altmask
5655 | "shift" -> Wsi.shiftmask
5656 | "ctrl" | "control" -> Wsi.ctrlmask
5657 | "meta" -> Wsi.metamask
5662 let r = Str.regexp
"-" in
5664 let elems = Str.full_split
r s in
5667 let m1 = modifier_of_string s in
5669 then (Wsi.namekey
s, m)
5672 | Str.Delim
s when n land 1 = 0 -> g s
5674 | Str.Delim
_ -> (k
, m)
5676 let rec loop n k
m = function
5679 let k, m = f n k m x in
5685 let keys_of_string =
5686 let r = Str.regexp
"[ \t]" in
5688 let elems = Str.split
r s in
5689 List.map
key_of_string elems
5692 let copykeyhashes c =
5693 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5696 let config_of c attrs
=
5700 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5701 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5702 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5703 | "preload" -> { c with preload = bool_of_string
v }
5704 | "page-bias" -> { c with pagebias
= int_of_string
v }
5705 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5706 | "auto-scroll-step" ->
5707 { c with autoscrollstep
= max
0 (int_of_string
v) }
5708 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5709 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5712 match String.lowercase
v with
5713 | "true" -> Some infinity
5715 | f -> Some
(float_of_string
f)
5717 { c with maxwait
= mw}
5718 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5719 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5720 | "vertical-margin" ->
5721 { c with interpagespace = max
0 (int_of_string
v) }
5723 let zoom = float_of_string
v /. 100. in
5724 let zoom = max
zoom 0.0 in
5725 { c with zoom = zoom }
5726 | "presentation" -> { c with presentation = bool_of_string
v }
5727 | "rotation-angle" -> { c with angle
= int_of_string
v }
5728 | "width" -> { c with winw = max
20 (int_of_string
v) }
5729 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5730 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5731 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5732 | "pixmap-cache-size" ->
5733 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5734 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5735 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5736 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5737 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5738 | "background-color" -> { c with bgcolor
= color_of_string v }
5739 | "scrollbar-in-presentation" ->
5740 { c with scrollbarinpm
= bool_of_string
v }
5741 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5742 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5743 | "mupdf-store-size" ->
5744 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5745 | "checkers" -> { c with checkers
= bool_of_string
v }
5746 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5747 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5748 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5749 | "uri-launcher" -> { c with urilauncher
= unent v }
5750 | "path-launcher" -> { c with pathlauncher
= unent v }
5751 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5752 | "invert-colors" -> { c with invert
= bool_of_string
v }
5753 | "brightness" -> { c with colorscale
= float_of_string
v }
5754 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5756 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5758 let (n, _, _) as nab
= multicolumns_of_string v in
5760 then { c with columns
= Csplit
(-n, [||]) }
5761 else { c with columns
= Cmulti
(nab
, [||]) }
5762 | "birds-eye-columns" ->
5763 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5764 | "selection-command" -> { c with selcmd
= unent v }
5765 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5768 prerr_endline
("Error processing attribute (`" ^
5769 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5772 let rec fold c = function
5775 let c = apply c k v in
5778 fold { c with keyhashes
= copykeyhashes c } attrs
;
5781 let fromstring f pos
n v d =
5784 dolog "Error processing attribute (%S=%S) at %d\n%s"
5785 n v pos
(Printexc.to_string exn
)
5790 let bookmark_of attrs
=
5791 let rec fold title page
rely = function
5792 | ("title", v) :: rest
-> fold v page
rely rest
5793 | ("page", v) :: rest
-> fold title v rely rest
5794 | ("rely", v) :: rest
-> fold title page
v rest
5795 | _ :: rest
-> fold title page
rely rest
5796 | [] -> title, page
, rely
5798 fold "invalid" "0" "0" attrs
5802 let rec fold path page
rely pan
= function
5803 | ("path", v) :: rest
-> fold v page
rely pan rest
5804 | ("page", v) :: rest
-> fold path v rely pan rest
5805 | ("rely", v) :: rest
-> fold path page
v pan rest
5806 | ("pan", v) :: rest
-> fold path page
rely v rest
5807 | _ :: rest
-> fold path page
rely pan rest
5808 | [] -> path, page
, rely, pan
5810 fold "" "0" "0" "0" attrs
5814 let rec fold rs ls
= function
5815 | ("out", v) :: rest
-> fold v ls rest
5816 | ("in", v) :: rest
-> fold rs
v rest
5817 | _ :: rest
-> fold ls rs rest
5823 let setconf dst
src =
5824 dst
.scrollbw
<- src.scrollbw
;
5825 dst
.scrollh
<- src.scrollh
;
5826 dst
.icase
<- src.icase
;
5827 dst
.preload <- src.preload;
5828 dst
.pagebias
<- src.pagebias
;
5829 dst
.verbose
<- src.verbose
;
5830 dst
.scrollstep
<- src.scrollstep
;
5831 dst
.maxhfit
<- src.maxhfit
;
5832 dst
.crophack
<- src.crophack
;
5833 dst
.autoscrollstep
<- src.autoscrollstep
;
5834 dst
.maxwait
<- src.maxwait
;
5835 dst
.hlinks
<- src.hlinks
;
5836 dst
.underinfo
<- src.underinfo
;
5837 dst
.interpagespace <- src.interpagespace;
5838 dst
.zoom <- src.zoom;
5839 dst
.presentation <- src.presentation;
5840 dst
.angle
<- src.angle
;
5841 dst
.winw <- src.winw;
5842 dst
.winh
<- src.winh
;
5843 dst
.savebmarks
<- src.savebmarks
;
5844 dst
.memlimit
<- src.memlimit
;
5845 dst
.proportional
<- src.proportional
;
5846 dst
.texcount
<- src.texcount
;
5847 dst
.sliceheight
<- src.sliceheight
;
5848 dst
.thumbw
<- src.thumbw
;
5849 dst
.jumpback
<- src.jumpback
;
5850 dst
.bgcolor
<- src.bgcolor
;
5851 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5852 dst
.tilew
<- src.tilew
;
5853 dst
.tileh
<- src.tileh
;
5854 dst
.mustoresize
<- src.mustoresize
;
5855 dst
.checkers
<- src.checkers
;
5856 dst
.aalevel
<- src.aalevel
;
5857 dst
.trimmargins
<- src.trimmargins
;
5858 dst
.trimfuzz
<- src.trimfuzz
;
5859 dst
.urilauncher
<- src.urilauncher
;
5860 dst
.colorspace
<- src.colorspace
;
5861 dst
.invert
<- src.invert
;
5862 dst
.colorscale
<- src.colorscale
;
5863 dst
.redirectstderr <- src.redirectstderr;
5864 dst
.ghyllscroll
<- src.ghyllscroll
;
5865 dst
.columns
<- src.columns
;
5866 dst
.beyecolumns
<- src.beyecolumns
;
5867 dst
.selcmd
<- src.selcmd
;
5868 dst
.updatecurs
<- src.updatecurs
;
5869 dst
.pathlauncher
<- src.pathlauncher
;
5870 dst
.keyhashes
<- copykeyhashes src;
5874 let h = Hashtbl.create
10 in
5875 let dc = { defconf with angle
= defconf.angle
} in
5876 let rec toplevel v t spos
_ =
5878 | Vdata
| Vcdata
| Vend
-> v
5879 | Vopen
("llppconfig", _, closed
) ->
5882 else { v with f = llppconfig
}
5884 error
"unexpected subelement at top level" s spos
5885 | Vclose
_ -> error
"unexpected close at top level" s spos
5887 and llppconfig
v t spos
_ =
5889 | Vdata
| Vcdata
-> v
5890 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5891 | Vopen
("defaults", attrs
, closed
) ->
5892 let c = config_of dc attrs
in
5896 else { v with f = defaults
}
5898 | Vopen
("ui-font", attrs
, closed
) ->
5899 let rec getsize size
= function
5901 | ("size", v) :: rest
->
5903 fromstring int_of_string spos
"size" v fstate.fontsize
in
5905 | l -> getsize size l
5907 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5910 else { v with f = uifont
(Buffer.create
10) }
5912 | Vopen
("doc", attrs
, closed
) ->
5913 let pathent, spage
, srely
, span
= doc_of attrs
in
5914 let path = unent pathent
5915 and pageno = fromstring int_of_string spos
"page" spage
0
5916 and rely = fromstring float_of_string spos
"rely" srely
0.0
5917 and pan
= fromstring int_of_string spos
"pan" span
0 in
5918 let c = config_of dc attrs
in
5919 let anchor = (pageno, rely) in
5921 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5922 else { v with f = doc
path pan
anchor c [] }
5925 error
"unexpected subelement in llppconfig" s spos
5927 | Vclose
"llppconfig" -> { v with f = toplevel }
5928 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5930 and defaults
v t spos
_ =
5932 | Vdata
| Vcdata
-> v
5933 | Vend
-> error
"unexpected end of input in defaults" s spos
5934 | Vopen
("keymap", attrs
, closed
) ->
5936 try List.assoc
"mode" attrs
5937 with Not_found
-> "global" in
5942 let h = findkeyhash dc modename in
5943 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5946 { v with f = pkeymap
ret KeyMap.empty }
5948 | Vopen
(_, _, _) ->
5949 error
"unexpected subelement in defaults" s spos
5951 | Vclose
"defaults" ->
5952 { v with f = llppconfig
}
5954 | Vclose
_ -> error
"unexpected close in defaults" s spos
5956 and uifont
b v t spos
epos =
5959 Buffer.add_substring
b s spos
(epos - spos
);
5961 | Vopen
(_, _, _) ->
5962 error
"unexpected subelement in ui-font" s spos
5963 | Vclose
"ui-font" ->
5964 if String.length
!fontpath = 0
5965 then fontpath := Buffer.contents
b;
5966 { v with f = llppconfig
}
5967 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5968 | Vend
-> error
"unexpected end of input in ui-font" s spos
5970 and doc
path pan
anchor c bookmarks
v t spos
_ =
5972 | Vdata
| Vcdata
-> v
5973 | Vend
-> error
"unexpected end of input in doc" s spos
5974 | Vopen
("bookmarks", _, closed
) ->
5977 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5979 | Vopen
("keymap", attrs
, closed
) ->
5981 try List.assoc
"mode" attrs
5982 with Not_found
-> "global"
5988 let h = findkeyhash c modename in
5989 KeyMap.iter
(Hashtbl.replace
h) keymap
;
5990 doc
path pan
anchor c bookmarks
5992 { v with f = pkeymap
ret KeyMap.empty }
5994 | Vopen
(_, _, _) ->
5995 error
"unexpected subelement in doc" s spos
5998 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5999 { v with f = llppconfig
}
6001 | Vclose
_ -> error
"unexpected close in doc" s spos
6003 and pkeymap
ret keymap
v t spos
_ =
6005 | Vdata
| Vcdata
-> v
6006 | Vend
-> error
"unexpected end of input in keymap" s spos
6007 | Vopen
("map", attrs
, closed
) ->
6008 let r, l = map_of attrs
in
6009 let kss = fromstring keys_of_string spos
"in" r [] in
6010 let lss = fromstring keys_of_string spos
"out" l [] in
6014 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6015 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6018 then { v with f = pkeymap
ret keymap }
6021 { v with f = skip
"map" f }
6024 error
"unexpected subelement in keymap" s spos
6026 | Vclose
"keymap" ->
6027 { v with f = ret keymap }
6029 | Vclose
_ -> error
"unexpected close in keymap" s spos
6031 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6033 | Vdata
| Vcdata
-> v
6034 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6035 | Vopen
("item", attrs
, closed
) ->
6036 let titleent, spage
, srely
= bookmark_of attrs
in
6037 let page = fromstring int_of_string spos
"page" spage
0
6038 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6039 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6041 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6044 { v with f = skip
"item" f }
6047 error
"unexpected subelement in bookmarks" s spos
6049 | Vclose
"bookmarks" ->
6050 { v with f = doc
path pan
anchor c bookmarks }
6052 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6054 and skip tag
f v t spos
_ =
6056 | Vdata
| Vcdata
-> v
6058 error
("unexpected end of input in skipped " ^ tag
) s spos
6059 | Vopen
(tag'
, _, closed
) ->
6063 let f'
() = { v with f = skip tag
f } in
6064 { v with f = skip tag'
f'
}
6068 else error
("unexpected close in skipped " ^ tag
) s spos
6071 parse
{ f = toplevel; accu = () } s;
6077 let len = in_channel_length ic
in
6078 let s = String.create
len in
6079 really_input ic
s 0 len;
6082 | Parse_error
(msg
, s, pos
) ->
6083 let subs = subs s pos
in
6084 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6085 failwith
("parse error: " ^
s)
6088 failwith
("config load error: " ^
Printexc.to_string exn
)
6094 let dir = Filename.concat
home ".config" in
6095 if Sys.is_directory
dir then dir else home
6098 Filename.concat
dir "llpp.conf"
6101 let confpath = ref defconfpath;;
6104 if Sys.file_exists
!confpath
6107 (try Some
(open_in_bin
!confpath)
6110 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6111 Printexc.to_string exn
);
6120 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6121 Printexc.to_string exn
);
6127 f (Hashtbl.create
0, defconf)
6132 let pc, pb
, px, pa
=
6134 Hashtbl.find h (Filename.basename
state.path)
6135 with Not_found
-> dc, [], 0, (0, 0.0)
6139 state.bookmarks <- pb
;
6141 state.scrollw
<- conf.scrollbw
;
6143 then state.anchor <- pa
;
6144 cbput state.hists
.nav pa
;
6149 let add_attrs bb always
dc c =
6152 then Printf.bprintf bb
"\n %s='%b'" s a
6155 then Printf.bprintf bb
"\n %s='%d'" s a
6158 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6161 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6164 then Printf.bprintf bb
"\n %s='%f'" s a
6168 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6172 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6176 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6180 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6186 | Some
(_N
, _A
, _B
) ->
6187 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6197 else string_of_float
f
6199 Printf.bprintf bb
"\n %s='%s'" s v
6204 | Cmulti
((n, a, b), _) when n > 1 ->
6205 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6206 | Csplit
(n, _) when n > 1 ->
6207 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6213 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6218 then dc.winw, dc.winh
6220 match state.fullscreen
with
6222 | None
-> c.winw, c.winh
6224 let zoom, presentation, interpagespace, maxwait
=
6226 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6228 match state.mode with
6229 | Birdseye
(bc
, _, _, _, _) ->
6230 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6231 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6233 oi
"width" w dc.winw;
6234 oi
"height" h dc.winh
;
6235 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6236 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6237 ob "case-insensitive-search" c.icase
dc.icase
;
6238 ob "preload" c.preload dc.preload;
6239 oi
"page-bias" c.pagebias
dc.pagebias
;
6240 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6241 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6242 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6243 ob "crop-hack" c.crophack
dc.crophack
;
6244 oW
"throttle" maxwait
dc.maxwait
;
6245 ob "highlight-links" c.hlinks
dc.hlinks
;
6246 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6247 oi
"vertical-margin" interpagespace dc.interpagespace;
6248 oz
"zoom" zoom dc.zoom;
6249 ob "presentation" presentation dc.presentation;
6250 oi
"rotation-angle" c.angle
dc.angle
;
6251 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6252 ob "proportional-display" c.proportional
dc.proportional
;
6253 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6254 oi
"tex-count" c.texcount
dc.texcount
;
6255 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6256 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6257 ob "persistent-location" c.jumpback
dc.jumpback
;
6258 oc
"background-color" c.bgcolor
dc.bgcolor
;
6259 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6260 oi
"tile-width" c.tilew
dc.tilew
;
6261 oi
"tile-height" c.tileh
dc.tileh
;
6262 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6263 ob "checkers" c.checkers
dc.checkers
;
6264 oi
"aalevel" c.aalevel
dc.aalevel
;
6265 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6266 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6267 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6268 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6269 oC
"color-space" c.colorspace
dc.colorspace
;
6270 ob "invert-colors" c.invert
dc.invert
;
6271 oF
"brightness" c.colorscale
dc.colorscale
;
6272 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6273 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6274 oco
"columns" c.columns
dc.columns
;
6275 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6276 os
"selection-command" c.selcmd
dc.selcmd
;
6277 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6280 let keymapsbuf always
dc c =
6281 let bb = Buffer.create
16 in
6282 let rec loop = function
6284 | (modename, h) :: rest
->
6285 let dh = findkeyhash dc modename in
6286 if always
|| h <> dh
6288 if Hashtbl.length
h > 0
6290 if Buffer.length
bb > 0
6291 then Buffer.add_char
bb '
\n'
;
6292 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6293 Hashtbl.iter
(fun i
o ->
6294 let isdifferent = always
||
6296 let dO = Hashtbl.find dh i
in
6298 with Not_found
-> true
6303 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6304 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6305 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6306 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6307 Buffer.add_string
bb (Wsi.keyname
k);
6310 let rec loop = function
6312 | km
:: [] -> addkm km
6313 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6317 Buffer.add_string
bb "<map in='";
6321 Buffer.add_string
bb "' out='";
6323 Buffer.add_string
bb "'/>\n"
6326 Buffer.add_string
bb "' out='";
6328 Buffer.add_string
bb "'/>\n"
6330 | KMmulti
(ins, kms
) ->
6331 Buffer.add_char
bb ' '
;
6333 Buffer.add_string
bb "' out='";
6335 Buffer.add_string
bb "'/>\n"
6337 Buffer.add_string
bb "</keymap>";
6347 let uifontsize = fstate.fontsize
in
6348 let bb = Buffer.create
32768 in
6350 let dc = if conf.bedefault
then conf else dc in
6351 Buffer.add_string
bb "<llppconfig>\n";
6353 if String.length
!fontpath > 0
6355 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6361 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6364 Buffer.add_string
bb "<defaults ";
6365 add_attrs bb true dc dc;
6366 let kb = keymapsbuf true dc dc in
6367 if Buffer.length
kb > 0
6369 Buffer.add_string
bb ">\n";
6370 Buffer.add_buffer
bb kb;
6371 Buffer.add_string
bb "\n</defaults>\n";
6373 else Buffer.add_string
bb "/>\n";
6375 let adddoc path pan
anchor c bookmarks =
6376 if bookmarks == [] && c = dc && anchor = emptyanchor
6379 Printf.bprintf
bb "<doc path='%s'"
6380 (enent
path 0 (String.length
path));
6382 if anchor <> emptyanchor
6384 let n, y = anchor in
6385 Printf.bprintf
bb " page='%d'" n;
6388 Printf.bprintf
bb " rely='%f'" y
6393 then Printf.bprintf
bb " pan='%d'" pan
;
6395 add_attrs bb false dc c;
6396 let kb = keymapsbuf false dc c in
6398 begin match bookmarks with
6400 if Buffer.length
kb > 0
6402 Buffer.add_string
bb ">\n";
6403 Buffer.add_buffer
bb kb;
6404 Buffer.add_string
bb "</doc>\n";
6406 else Buffer.add_string
bb "/>\n"
6408 Buffer.add_string
bb ">\n<bookmarks>\n";
6409 List.iter
(fun (title, _level
, (page, rely)) ->
6411 "<item title='%s' page='%d'"
6412 (enent
title 0 (String.length
title))
6417 Printf.bprintf
bb " rely='%f'" rely
6419 Buffer.add_string
bb "/>\n";
6421 Buffer.add_string
bb "</bookmarks>";
6422 if Buffer.length
kb > 0
6424 Buffer.add_string
bb "\n";
6425 Buffer.add_buffer
bb kb;
6427 Buffer.add_string
bb "\n</doc>\n";
6433 match state.mode with
6434 | Birdseye
(c, pan, _, _, _) ->
6436 match conf.columns
with
6437 | Cmulti
((c, _, _), _) -> Some
c
6441 match c.columns
with
6442 | Cmulti
(c, _) -> Cmulti
(c, [||])
6443 | Csingle
-> Csingle
6444 | Csplit
_ -> failwith
"quit from bird's eye while split"
6446 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6447 | _ -> state.x, conf
6449 let basename = Filename.basename state.path in
6450 adddoc basename pan (getanchor ())
6453 match state.autoscroll
with
6455 | None
-> conf.autoscrollstep
}
6456 (if conf.savebmarks
then state.bookmarks else []);
6458 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6460 then adddoc path x y c bookmarks
6462 Buffer.add_string
bb "</llppconfig>";
6465 if Buffer.length
bb > 0
6468 let tmp = !confpath ^
".tmp" in
6469 let oc = open_out_bin
tmp in
6470 Buffer.output_buffer
oc bb;
6472 Unix.rename
tmp !confpath;
6475 ("error while saving configuration: " ^
Printexc.to_string exn
)
6482 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6483 "<password> Set password");
6485 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6486 "<path> Set path to the user interface font");
6488 ("-c", Arg.String
(fun s -> Config.confpath := s),
6489 "<path> Set path to the configuration file");
6491 ("-v", Arg.Unit
(fun () ->
6493 "%s\nconfiguration path: %s\n"
6497 exit
0), " Print version and exit");
6500 (fun s -> state.path <- s)
6501 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6503 if String.length
state.path = 0
6504 then (prerr_endline
"file name missing"; exit
1);
6508 let globalkeyhash = findkeyhash conf "global" in
6509 let wsfd, winw, winh
= Wsi.init
(object
6511 if nogeomcmds state.geomcmds
6513 method display = display ()
6514 method reshape w h = reshape w h
6515 method mouse b d x y m = mouse b d x y m
6516 method motion x y = state.mpos
<- (x, y); motion x y
6517 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6519 let mascm = m land (
6520 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6522 match state.keystate
with
6524 let km = k, mascm in
6527 try Hashtbl.find globalkeyhash km
6529 let modehash = state.uioh#
modehash in
6530 try Hashtbl.find modehash km
6531 with Not_found
-> KMinsrt
(k, m)
6533 | KMinsrt
(k, m) -> keyboard k m
6534 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6535 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6537 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6538 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6539 state.keystate
<- KSnone
6540 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6541 state.keystate
<- KSinto
(keys
, insrt
)
6543 state.keystate
<- KSnone
6545 method enter
x y = state.mpos
<- (x, y); pmotion x y
6546 method leave = state.mpos
<- (-1, -1)
6547 method quit
= raise Quit
6548 end) conf.winw conf.winh
(platform = Posx
) in
6553 List.exists
GlMisc.check_extension
6554 [ "GL_ARB_texture_rectangle"
6555 ; "GL_EXT_texture_recangle"
6556 ; "GL_NV_texture_rectangle" ]
6558 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6560 let cr, sw = Unix.pipe
()
6561 and sr
, cw = Unix.pipe
() in
6568 setcheckers conf.checkers
;
6572 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6573 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6578 state.text <- "Opening " ^
state.path;
6580 opendoc state.path state.password
;
6583 let rec loop deadline
=
6585 match state.errfd
with
6586 | None
-> [state.sr
; state.wsfd]
6587 | Some fd
-> [state.sr
; state.wsfd; fd
]
6591 state.redisplay
<- false;
6598 if deadline
= infinity
6600 else max
0.0 (deadline
-. now)
6605 try Unix.select
r [] [] timeout
6606 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6612 if state.ghyll
== noghyll
6614 match state.autoscroll
with
6615 | Some step
when step
!= 0 ->
6616 let y = state.y + step
in
6620 else if y >= state.maxy then 0 else y
6623 if state.mode = View
6624 then state.text <- "";
6627 else deadline
+. 0.01
6632 let rec checkfds = function
6634 | fd
:: rest
when fd
= state.sr
->
6635 let cmd = readcmd state.sr
in
6639 | fd
:: rest
when fd
= state.wsfd ->
6644 let s = String.create
80 in
6645 let n = Unix.read fd
s 0 80 in
6646 if conf.redirectstderr
6648 Buffer.add_substring
state.errmsgs
s 0 n;
6649 state.newerrmsgs
<- true;
6650 state.redisplay
<- true;
6653 prerr_string
(String.sub
s 0 n);
6661 if deadline
= infinity
6665 match state.autoscroll
with
6666 | Some step
when step
!= 0 -> deadline1
6667 | _ -> if state.ghyll
== noghyll then infinity
else deadline1