4 | Ulinkgoto
of (int * int)
6 and facename
= string;;
8 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
9 let dolog2 fmt
= Printf.kprintf print_endline fmt
;;
10 let now = Unix.gettimeofday
;;
14 type params
= (angle
* proportional
* trimparams
15 * texcount
* sliceheight
* memsize
16 * colorspace
* wmclasshack
* fontpath
)
25 and proportional
= bool
26 and trimmargins
= bool
27 and interpagespace
= int
35 and wmclasshack
= bool
36 and irect
= (int * int * int * int)
37 and trimparams
= (trimmargins
* irect
)
38 and colorspace
= | Rgb
| Bgr
| Gray
41 type platform
= | Punknown
| Plinux
| Pwindows
| Posx
| Psun
42 | Pfreebsd
| Pdragonflybsd
| Popenbsd
| Pmingw
| Pcygwin
;;
44 external init
: Unix.file_descr
-> params
-> unit = "ml_init";;
45 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
46 external copysel
: string -> unit = "ml_copysel";;
47 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
48 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
49 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
50 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
51 external measurestr
: int -> string -> float = "ml_measure_string";;
52 external getmaxw
: unit -> float = "ml_getmaxw";;
53 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
54 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
55 external platform
: unit -> platform
= "ml_platform";;
56 external setaalevel
: int -> unit = "ml_setaalevel";;
58 let platform_to_string = function
59 | Punknown
-> "unknown"
61 | Pwindows
-> "Windows"
64 | Pfreebsd
-> "FreeBSD"
65 | Pdragonflybsd
-> "DragonflyBSD"
66 | Popenbsd
-> "OpenBSD"
71 let platform = platform ();;
75 | Pwindows
| Pmingw
-> true
83 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
86 external drawtile
: tileparams
-> string -> unit = "ml_drawtile";;
90 | Msel
of (mpos
* mpos
)
93 | Mzoom
of (int * int)
94 | Mzoomrect
of (mpos
* mpos
)
98 type textentry
= string * string * onhist
option * onkey
* ondone
99 and onkey
= string -> int -> te
100 and ondone
= string -> unit
101 and histcancel
= unit -> unit
102 and onhist
= ((histcmd
-> string) * histcancel
)
103 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
108 | TEswitch
of textentry
119 let bound v minv maxv
=
120 max minv
(min maxv v
);
124 { store
= Array.create n v
131 let drawstring size x y s
=
133 Gl.enable `texture_2d
;
134 ignore
(drawstr size x y s
);
136 Gl.disable `texture_2d
;
139 let drawstring1 size x y s
=
143 let drawstring2 size x y fmt
=
144 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
147 let cbcap b
= Array.length b
.store
;;
152 b
.wc
<- (b
.wc
+ 1) mod cap;
154 b
.len
<- min
(b
.len
+ 1) cap;
157 let cbempty b
= b
.len
= 0;;
159 let cbgetg b circular dir
=
163 let rc = b
.rc + dir
in
175 else max
0 (min
rc (b
.len
-1))
181 let cbget b
= cbgetg b
false;;
182 let cbgetc b
= cbgetg b
true;;
199 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
200 dolog " WxH %dx%d" l
.pagew l
.pageh
;
201 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
202 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
203 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
207 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
209 dolog " x0,y0=(% f, % f)" x0 y0
;
210 dolog " x1,y1=(% f, % f)" x1 y1
;
211 dolog " x2,y2=(% f, % f)" x2 y2
;
212 dolog " x3,y3=(% f, % f)" x3 y3
;
217 { mutable scrollbw
: int
218 ; mutable scrollh
: int
219 ; mutable icase
: bool
220 ; mutable preload
: bool
221 ; mutable pagebias
: int
222 ; mutable verbose
: bool
223 ; mutable debug
: bool
224 ; mutable scrollstep
: int
225 ; mutable maxhfit
: bool
226 ; mutable crophack
: bool
227 ; mutable autoscrollstep
: int
228 ; mutable maxwait
: float option
229 ; mutable hlinks
: bool
230 ; mutable underinfo
: bool
231 ; mutable interpagespace
: interpagespace
232 ; mutable zoom
: float
233 ; mutable presentation
: bool
234 ; mutable angle
: angle
237 ; mutable savebmarks
: bool
238 ; mutable proportional
: proportional
239 ; mutable trimmargins
: trimmargins
240 ; mutable trimfuzz
: irect
241 ; mutable memlimit
: memsize
242 ; mutable texcount
: texcount
243 ; mutable sliceheight
: sliceheight
244 ; mutable thumbw
: width
245 ; mutable jumpback
: bool
246 ; mutable bgcolor
: float * float * float
247 ; mutable bedefault
: bool
248 ; mutable scrollbarinpm
: bool
249 ; mutable tilew
: int
250 ; mutable tileh
: int
251 ; mutable mumemlimit
: memsize
252 ; mutable checkers
: bool
253 ; mutable aalevel
: int
254 ; mutable urilauncher
: string
255 ; mutable colorspace
: colorspace
256 ; mutable invert
: bool
257 ; mutable colorscale
: float
258 ; mutable redirectstderr
: bool
262 type anchor
= pageno
* top
;;
264 type outline
= string * int * anchor
;;
266 type rect
= float * float * float * float * float * float * float * float;;
268 type tile
= opaque
* pixmapsize
* elapsed
269 and elapsed
= float;;
270 type pagemapkey
= pageno
* gen
;;
271 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
275 let emptyanchor = (0, 0.0);;
277 type infochange
= | Memused
| Docinfo
| Pdim
;;
279 class type uioh
= object
280 method display
: unit
281 method key
: int -> uioh
282 method special
: Glut.special_key_t
-> uioh
284 Glut.button_t
-> Glut.mouse_button_state_t
-> int -> int -> uioh
285 method motion
: int -> int -> uioh
286 method pmotion
: int -> int -> uioh
287 method infochanged
: infochange
-> unit
291 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
292 | Textentry
of (textentry
* onleave
)
294 and onleave
= leavetextentrystatus
-> unit
295 and leavetextentrystatus
= | Cancel
| Confirm
296 and helpitem
= string * int * action
299 | Action
of (uioh
-> uioh
)
302 let isbirdseye = function Birdseye _
-> true | _
-> false;;
303 let istextentry = function Textentry _
-> true | _
-> false;;
307 | Loading
of (page
* gen
)
309 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
311 | Outlining
of outline list
314 let nouioh : uioh
= object (self
)
317 method special _
= self
318 method button _ _ _ _
= self
319 method motion _ _
= self
320 method pmotion _ _
= self
321 method infochanged _
= ()
325 { mutable csock
: Unix.file_descr
326 ; mutable ssock
: Unix.file_descr
327 ; mutable errfd
: Unix.file_descr
328 ; mutable stderr
: Unix.file_descr
329 ; mutable errmsgs
: Buffer.t
330 ; mutable newerrmsgs
: bool
334 ; mutable scrollw
: int
335 ; mutable hscrollh
: int
336 ; mutable anchor
: anchor
338 ; mutable layout
: page list
339 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
340 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
341 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
342 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
343 ; mutable pagecount
: int
344 ; mutable currently
: currently
345 ; mutable mstate
: mstate
346 ; mutable searchpattern
: string
347 ; mutable rects
: (pageno
* recttype
* rect
) list
348 ; mutable rects1
: (pageno
* recttype
* rect
) list
349 ; mutable text
: string
350 ; mutable fullscreen
: (width
* height
) option
351 ; mutable mode
: mode
352 ; mutable uioh
: uioh
353 ; mutable outlines
: outline array
354 ; mutable bookmarks
: outline list
355 ; mutable path
: string
356 ; mutable password
: string
357 ; mutable invalidated
: int
358 ; mutable memused
: memsize
360 ; mutable throttle
: (page list
* int * float) option
361 ; mutable autoscroll
: int option
362 ; mutable help
: helpitem array
363 ; mutable docinfo
: (int * string) list
364 ; mutable deadline
: float
365 ; mutable texid
: GlTex.texture_id
option
367 ; mutable prevzoom
: float
368 ; mutable progress
: float
371 { pat
: string circbuf
372 ; pag
: string circbuf
373 ; nav
: anchor circbuf
394 ; presentation
= false
399 ; proportional
= true
400 ; trimmargins
= false
401 ; trimfuzz
= (0,0,0,0)
402 ; memlimit
= 32 lsl 20
407 ; bgcolor
= (0.5, 0.5, 0.5)
409 ; scrollbarinpm
= true
412 ; mumemlimit
= 128 lsl 20
417 | Plinux
| Pfreebsd
| Pdragonflybsd
| Popenbsd
| Psun
-> "xdg-open \"%s\""
418 | Posx
-> "open \"%s\""
419 | Pwindows
| Pcygwin
| Pmingw
-> "iexplore \"%s\""
424 ; redirectstderr
= false
428 let conf = { defconf with angle
= defconf.angle
};;
431 { mutable fontsize
: int
432 ; mutable wwidth
: float
433 ; mutable maxrows
: int
445 fstate.fontsize
<- n
;
446 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
447 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
451 if String.length
conf.urilauncher
= 0
452 then print_endline uri
454 let re = Str.regexp
"%s" in
455 let command = Str.global_replace
re uri
conf.urilauncher
in
457 try Some
(Unix.open_process_in
command)
460 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
465 | Some ic
-> close_in ic
470 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
471 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
475 let strings = version () :: "" :: Help.keys
in
477 let r = Str.regexp
"\\(http://[^ ]+\\)" in
479 if (try Str.search_forward
r s
0 with Not_found
-> -1) >= 0
481 let uri = Str.matched_string s
in
482 (s
, 0, Action
(fun u
-> gotouri uri; u
))
483 else s
, 0, Noaction
) strings
491 ; stderr
= Unix.stderr
492 ; errmsgs
= Buffer.create
0
499 ; anchor
= emptyanchor
502 ; tilelru
= Queue.create
()
503 ; pagemap
= Hashtbl.create
10
504 ; tilemap
= Hashtbl.create
10
521 { nav
= cbnew 10 (0, 0.0)
542 Printf.kprintf prerr_endline fmt
544 Printf.kprintf ignore fmt
547 let redirectstderr () =
548 if conf.redirectstderr
550 let rfd, wfd
= Unix.pipe
() in
551 state.stderr
<- Unix.dup
Unix.stderr
;
553 Unix.dup2 wfd
Unix.stderr
;
555 state.newerrmsgs
<- false;
556 Unix.dup2
state.stderr
Unix.stderr
;
557 prerr_string
(Buffer.contents
state.errmsgs
);
559 Buffer.clear
state.errmsgs
;
565 let postRedisplay who
=
567 then prerr_endline
("redisplay for " ^ who
);
568 Glut.postRedisplay ();
573 let b = Buffer.create
(String.length s
+ 1) in
574 Buffer.add_string
b s
;
579 let colorspace_of_string s
=
580 match String.lowercase s
with
584 | _
-> failwith
"invalid colorspace"
587 let int_of_colorspace = function
593 let colorspace_of_int = function
597 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
600 let colorspace_to_string = function
606 let intentry_with_suffix text key
=
607 let c = Char.unsafe_chr key
in
608 match Char.lowercase
c with
610 let text = addchar text c in
614 let text = addchar text c in
618 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
623 let len = String.length s
in
625 let b = Buffer.create
n in
626 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
627 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
628 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
629 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
630 Buffer.add_string
b s
;
631 let s'
= Buffer.contents
b in
632 let n'
= Unix.write fd
s'
0 n in
633 if n'
!= n then failwith
"write failed";
638 let n = Unix.read fd
s 0 4 in
639 if n != 4 then failwith
"incomplete read(len)";
641 lor (Char.code
s.[0] lsl 24)
642 lor (Char.code
s.[1] lsl 16)
643 lor (Char.code
s.[2] lsl 8)
644 lor (Char.code
s.[3] lsl 0)
646 let s = String.create
len in
647 let n = Unix.read fd
s 0 len in
648 if n != len then failwith
"incomplete read(data)";
653 let b = Buffer.create
10 in
654 Buffer.add_string
b s;
655 let rec combine = function
658 Buffer.add_char
b ' '
;
661 | `
b b -> if b then "1" else "0"
663 | `i i
-> string_of_int i
664 | `f f
-> string_of_float f
665 | `I f
-> string_of_int
(truncate f
)
667 Buffer.add_string
b s;
674 let cmd = Buffer.contents
(makecmd s l
) in
675 writecmd state.csock
cmd;
681 let d = conf.winh
- h
in
688 let rec f pn ph pi fh l
=
690 | (n, _
, h
, _
) :: rest
->
691 let ips = calcips h
in
696 if isbirdseye state.mode
&& pn
= 0
701 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
706 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
710 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
713 let fh = f 0 0 0 0 state.pdims
in
717 let getpageyh pageno
=
718 let rec f pn ph pi y l
=
720 | (n, _
, h
, _
) :: rest
->
721 let ips = calcips h
in
724 let h = if n = pageno
then h else ph
in
725 if conf.presentation
&& n = pageno
727 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
729 y
+ (pageno
- pn
) * (ph
+ pi
), h
731 let y = y + (if conf.presentation
then pi
else 0) in
732 let y = y + (n - pn
) * (ph
+ pi
) in
736 y + (pageno
- pn
) * (ph
+ pi
), ph
738 f 0 0 0 0 state.pdims
741 let getpagedim pageno
=
744 | (n, _
, _
, _
) as pdim
:: rest
->
746 then (if n = pageno
then pdim
else ppdim
)
751 f (-1, -1, -1, -1) state.pdims
754 let getpagey pageno
= fst
(getpageyh pageno
);;
757 let sh = sh - state.hscrollh
in
758 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
759 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
761 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
762 let ips = calcips h in
764 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
768 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
770 prev
, pdims
, pdimno
, 0
772 let dy = dy + yinc in
773 let py = py + yinc in
774 if pageno
= state.pagecount
|| dy >= sh
779 if py + h <= vy - yinc
781 let py = py + h + ips in
782 let dy = max
0 (py - y) in
791 let pagey = vy - py in
792 let pagevh = h - pagey in
793 let pagevh = min
(sh - dy) pagevh in
794 let off = if yinc > 0 then py - vy else 0 in
795 let py = py + h + ips in
798 if state.w
< conf.winw
- state.scrollw
799 then (conf.winw
- state.scrollw
- state.w
) / 2
802 let dispx = xoff + state.x
in
808 let lw = w
- pagex in
809 min
lw (conf.winw
- state.scrollw
)
817 ; pagey = pagey + off
819 ; pagevh = pagevh - off
821 ; pagedispy
= dy + off
824 let accu = e :: accu in
833 if state.invalidated
= 0
852 let y = state.y + incr
in
854 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
858 let getopaque pageno
=
859 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
860 with Not_found
-> None
863 let putopaque pageno opaque
=
864 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
868 let tilex = l
.pagex mod conf.tilew
in
869 let tiley = l
.pagey mod conf.tileh
in
871 let col = l
.pagex / conf.tilew
in
872 let row = l
.pagey / conf.tileh
in
875 let a = l
.pagew
- l
.pagex in
876 let b = conf.winw
- state.scrollw
in
880 let rec rowloop row y0 dispy
h =
884 let dh = conf.tileh
- y0
in
886 let rec colloop col x0
dispx w
=
890 let dw = conf.tilew
- x0
in
893 f col row dispx dispy x0 y0
dw dh;
894 colloop (col+1) 0 (dispx+dw) (w
-dw)
897 colloop col tilex l
.pagedispx
vw;
898 rowloop (row+1) 0 (dispy
+dh) (h-dh)
902 then rowloop row tiley l
.pagedispy vh
;
905 let gettileopaque l
col row =
907 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
909 try Some
(Hashtbl.find
state.tilemap
key)
910 with Not_found
-> None
913 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
914 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
915 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
918 let drawtiles l color
=
920 let f col row x
y tilex tiley w
h =
921 match gettileopaque l
col row with
922 | Some
(opaque
, _
, t
) ->
923 let params = x
, y, w
, h, tilex, tiley in
927 GlFunc.blend_func `zero `one_minus_src_color
;
929 drawtile
params opaque
;
931 then Gl.disable `blend
;
934 let s = Printf.sprintf
938 let ww = fstate.wwidth
in
939 GlMisc.push_attrib
[`current
];
940 GlDraw.color
(0.0, 0.0, 0.0);
942 (float (x
-2), float (y-2))
943 (float (x
+2) +. ww, float (y + fstate.fontsize
+ 2));
944 GlDraw.color
(1.0, 1.0, 1.0);
945 drawstring fstate.fontsize x
(y + fstate.fontsize
- 1) s;
946 GlMisc.pop_attrib
();
951 let lw = conf.winw
- state.scrollw
- x
in
954 let lh = conf.winh
- y in
957 Gl.enable `texture_2d
;
958 begin match state.texid
with
960 GlTex.bind_texture `texture_2d id
;
964 and y1
= float (y+h) in
966 let tw = float w /. 64.0
967 and th
= float h /. 64.0 in
968 let tx0 = float tilex /. 64.0
969 and ty0
= float tiley /. 64.0 in
971 and ty1
= ty0
+. th
in
972 GlDraw.begins `quads
;
973 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
974 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
975 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
976 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
979 Gl.disable `texture_2d
;
981 GlDraw.color
(1.0, 1.0, 1.0);
984 (float (x
+w), float (y+h));
986 if w > 128 && h > fstate.fontsize
+ 10
988 GlDraw.color
(0.0, 0.0, 0.0);
991 then (col*conf.tilew
, row*conf.tileh
)
994 drawstring2 fstate.fontsize x
y "Loading %d [%d,%d]" l
.pageno
c r;
1001 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1003 let tilevisible1 l x
y =
1005 and ax1
= l
.pagex + l
.pagevw
1007 and ay1
= l
.pagey + l
.pagevh in
1011 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1012 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1014 let rx0 = max
ax0 bx0
1015 and ry0
= max ay0 by0
1016 and rx1
= min ax1
bx1
1017 and ry1
= min ay1 by1
in
1019 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1020 nonemptyintersection
1023 let tilevisible layout n x
y =
1024 let rec findpageinlayout = function
1025 | l
:: _
when l
.pageno
= n -> tilevisible1 l x
y
1026 | _
:: rest
-> findpageinlayout rest
1029 findpageinlayout layout
1032 let tileready l x
y =
1033 tilevisible1 l x
y &&
1034 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
1037 let tilepage n p
layout =
1038 let rec loop = function
1042 let f col row _ _ _ _ _ _
=
1043 if state.currently
= Idle
1045 match gettileopaque l
col row with
1048 let x = col*conf.tilew
1049 and y = row*conf.tileh
in
1051 let w = l
.pagew
- x in
1055 let h = l
.pageh
- y in
1067 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1068 conf.tilew
, conf.tileh
1077 if state.invalidated
= 0 then loop layout;
1080 let preloadlayout visiblepages
=
1081 let presentation = conf.presentation in
1082 let interpagespace = conf.interpagespace in
1083 let maxy = state.maxy in
1084 conf.presentation <- false;
1085 conf.interpagespace <- 0;
1086 state.maxy <- calcheight ();
1088 match visiblepages
with
1090 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1092 let y = if y < conf.winh
then 0 else y - conf.winh
in
1093 let h = state.y - y + conf.winh
*3 in
1094 let pages = layout y h in
1095 conf.presentation <- presentation;
1096 conf.interpagespace <- interpagespace;
1102 let rec loop pages =
1103 if state.currently
!= Idle
1108 begin match getopaque l
.pageno
with
1110 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1111 state.currently
<- Loading
(l
, state.gen
);
1113 tilepage l
.pageno opaque
pages;
1118 if state.invalidated
= 0 then loop pages
1123 if conf.preload && state.currently
= Idle
1124 then load (preloadlayout pages);
1127 let layoutready layout =
1128 let rec fold all ls
=
1129 all
&& match ls
with
1131 let seen = ref false in
1132 let allvisible = ref true in
1133 let foo col row _ _ _ _ _ _
=
1135 allvisible := !allvisible &&
1136 begin match gettileopaque l
col row with
1142 fold (!seen && !allvisible) rest
1145 let alltilesvisible = fold true layout in
1150 let y = bound y 0 state.maxy in
1151 let y, layout, proceed
=
1152 match conf.maxwait
with
1154 begin match state.throttle
with
1156 let layout = layout y conf.winh
in
1157 let ready = layoutready layout in
1161 state.throttle
<- Some
(layout, y, now ());
1163 else G.postRedisplay "gotoy showall (None)";
1165 | Some
(_
, _
, started
) ->
1166 let dt = now () -. started
in
1169 state.throttle
<- None
;
1170 let layout = layout y conf.winh
in
1172 G.postRedisplay "maxwait";
1179 let layout = layout y conf.winh
in
1180 if true || layoutready layout
1181 then G.postRedisplay "gotoy ready";
1187 state.layout <- layout;
1188 begin match state.mode
with
1189 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1190 if not
(pagevisible layout pageno
)
1192 match state.layout with
1195 state.mode
<- Birdseye
(
1196 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1205 let conttiling pageno opaque
=
1206 tilepage pageno opaque
1207 (if conf.preload then preloadlayout state.layout else state.layout)
1210 let gotoy_and_clear_text y =
1212 if not
conf.verbose
then state.text <- "";
1216 match state.layout with
1218 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1221 let getanchory (n, top
) =
1222 let y, h = getpageyh n in
1223 y + (truncate
(top
*. float h));
1226 let gotoanchor anchor
=
1227 gotoy (getanchory anchor
);
1231 cbput state.hists
.nav
(getanchor ());
1235 let anchor = cbgetc state.hists
.nav dir
in
1239 let gotopage n top
=
1240 let y, h = getpageyh n in
1241 gotoy_and_clear_text (y + (truncate
(top
*. float h)));
1244 let gotopage1 n top
=
1245 let y = getpagey n in
1246 gotoy_and_clear_text (y + top
);
1254 state.invalidated
<- state.invalidated
+ 1;
1257 let writeopen path password
=
1258 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1261 let opendoc path password
=
1264 state.password
<- password
;
1265 state.gen
<- state.gen
+ 1;
1266 state.docinfo
<- [];
1268 setaalevel
conf.aalevel
;
1269 writeopen path password
;
1270 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1271 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1275 let c = c *. conf.colorscale
in
1279 let scalecolor2 (r, g
, b) =
1280 (r *. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1284 state.maxy <- calcheight ();
1286 if state.w <= conf.winw
- state.scrollw
1290 match state.mode
with
1291 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1292 let y, h = getpageyh pageno
in
1293 let top = (conf.winh
- h) / 2 in
1294 gotoy (max
0 (y - top))
1295 | _
-> gotoanchor state.anchor
1299 let firsttime = ref true in
1301 GlDraw.viewport
0 0 w h;
1302 if state.invalidated
= 0 && not
!firsttime
1303 then state.anchor <- getanchor ();
1307 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1311 setfontsize fstate.fontsize
;
1312 GlMat.mode `modelview
;
1313 GlMat.load_identity
();
1315 GlMat.mode `projection
;
1316 GlMat.load_identity
();
1317 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1318 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1319 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1322 wcmd "geometry" [`i
w; `i
h];
1326 let len = String.length
state.text in
1329 match state.mode
with
1330 | View
-> state.hscrollh
1335 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1336 (x+.w, float (conf.winh
- hscrollh))
1339 let w = float (conf.winw
- state.scrollw
- 1) in
1340 if state.progress
>= 0.0 && state.progress
< 1.0
1342 GlDraw.color
(0.3, 0.3, 0.3);
1343 let w1 = w *. state.progress
in
1345 GlDraw.color
(0.0, 0.0, 0.0);
1349 GlDraw.color
(0.0, 0.0, 0.0);
1353 GlDraw.color
(1.0, 1.0, 1.0);
1354 drawstring fstate.fontsize
1355 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1358 match state.mode
with
1359 | Textentry
((prefix
, text, _
, _
, _
), _
) ->
1363 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1365 Printf.sprintf
"%s%s_" prefix
text
1374 if not
(istextentry state.mode
)
1376 let s1 = "(press 'e' to review error messasges)" in
1377 if String.length
s > 0 then s ^
" " ^
s1 else s1
1382 if String.length
s > 0
1387 state.text <- Printf.sprintf
"%c%s" c s;
1388 G.postRedisplay "showtext";
1392 let len = Queue.length
state.tilelru
in
1394 if state.memused
<= conf.memlimit
1399 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1400 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1401 let (_
, pw
, ph
, _
) = getpagedim n in
1404 && colorspace
= conf.colorspace
1405 && angle
= conf.angle
1410 match state.throttle
with
1413 then preloadlayout state.layout
1415 | Some
(layout, _
, _
) ->
1418 let x = col*conf.tilew
1419 and y = row*conf.tileh
in
1420 tilevisible layout n x y
1422 then Queue.push lruitem
state.tilelru
1424 wcmd "freetile" [`
s p
];
1425 state.memused
<- state.memused
- s;
1426 state.uioh#infochanged Memused
;
1427 Hashtbl.remove
state.tilemap k
;
1436 Queue.iter
(fun (k
, p
, s) ->
1437 wcmd "freetile" [`
s p
];
1438 state.memused
<- state.memused
- s;
1439 state.uioh#infochanged Memused
;
1440 Hashtbl.remove
state.tilemap k
;
1442 Queue.clear
state.tilelru
;
1446 let logcurrently = function
1447 | Idle
-> dolog "Idle"
1448 | Loading
(l
, gen
) ->
1449 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1450 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1452 "Tiling %d[%d,%d] page=%s cs=%s angle"
1453 l
.pageno
col row pageopaque
1454 (colorspace_to_string colorspace
)
1456 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1457 angle gen
conf.angle
state.gen
1459 conf.tilew
conf.tileh
1466 (* dolog "%S" cmds; *)
1469 try String.index cmds ' '
1470 with Not_found
-> -1
1475 let l = String.length cmds
in
1476 let op = String.sub cmds
0 spacepos in
1478 if l - spacepos < 2 then ""
1479 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1484 state.uioh#infochanged Pdim
;
1488 state.rects
<- state.rects1
;
1489 G.postRedisplay "clearrects";
1493 try Scanf.sscanf args
"%u" (fun n -> n)
1495 dolog "error processing 'continue' %S: %s"
1496 cmds
(Printexc.to_string exn
);
1499 state.pagecount
<- n;
1500 state.invalidated
<- state.invalidated
- 1;
1501 begin match state.currently
with
1503 state.currently
<- Idle
;
1504 state.outlines
<- Array.of_list
(List.rev
l)
1507 if state.invalidated
= 0
1509 if conf.maxwait
= None
1510 then G.postRedisplay "continue";
1513 Glut.setWindowTitle args
1520 then showtext ' ' args
1523 let progress, text =
1525 Scanf.sscanf args
"%f %n"
1527 f, String.sub args pos
(String.length args
- pos
))
1529 dolog "error processing 'progress' %S: %s"
1530 cmds
(Printexc.to_string exn
);
1534 state.progress <- progress;
1535 G.postRedisplay "progress"
1538 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1540 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1541 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1542 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1544 dolog "error processing 'firstmatch' %S: %s"
1545 cmds
(Printexc.to_string exn
);
1548 let y = (getpagey pageno) + truncate y0
in
1551 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)]
1554 let pageno, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
1556 Scanf.sscanf args
"%u %d %f %f %f %f %f %f %f %f"
1557 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1558 (p
, c, x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
1560 dolog "error processing 'match' %S: %s"
1561 cmds
(Printexc.to_string exn
);
1565 (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) :: state.rects1
1570 Scanf.sscanf args
"%s %f" (fun p t
-> p
, t
)
1572 dolog "error processing 'page' %S: %s"
1573 cmds
(Printexc.to_string exn
);
1576 begin match state.currently
with
1577 | Loading
(l, gen
) ->
1578 vlog "page %d took %f sec" l.pageno t
;
1579 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1580 begin match state.throttle
with
1582 let preloadedpages =
1584 then preloadlayout state.layout
1589 Set.Make
(struct type t
= int let compare = (-) end) in
1591 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1592 IntSet.empty
preloadedpages
1595 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
1596 if not
(IntSet.mem
pageno set)
1598 wcmd "freepage" [`
s opaque
];
1604 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1607 state.currently
<- Idle
;
1610 tilepage l.pageno pageopaque state.layout;
1612 load preloadedpages;
1613 if pagevisible state.layout l.pageno
1614 && layoutready state.layout
1615 then G.postRedisplay "page";
1618 | Some
(layout, _
, _
) ->
1619 state.currently
<- Idle
;
1620 tilepage l.pageno pageopaque layout;
1625 dolog "Inconsistent loading state";
1626 logcurrently state.currently
;
1631 let (x, y, opaque
, size
, t
) =
1633 Scanf.sscanf args
"%u %u %s %u %f"
1634 (fun x y p size t
-> (x, y, p
, size
, t
))
1636 dolog "error processing 'tile' %S: %s"
1637 cmds
(Printexc.to_string exn
);
1640 begin match state.currently
with
1641 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1642 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1644 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1646 wcmd "freetile" [`
s opaque
];
1647 state.currently
<- Idle
;
1651 puttileopaque l col row gen cs angle opaque size t
;
1652 state.memused
<- state.memused
+ size
;
1653 state.uioh#infochanged Memused
;
1655 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1656 opaque
, size
) state.tilelru
;
1659 match state.throttle
with
1660 | None
-> state.layout
1661 | Some
(layout, _
, _
) -> layout
1664 state.currently
<- Idle
;
1666 && conf.colorspace
= cs
1667 && conf.angle
= angle
1668 && tilevisible layout l.pageno x y
1669 then conttiling l.pageno pageopaque;
1671 begin match state.throttle
with
1673 preload state.layout;
1675 && conf.colorspace
= cs
1676 && conf.angle
= angle
1677 && tilevisible state.layout l.pageno x y
1678 then G.postRedisplay "tile nothrottle";
1680 | Some
(layout, y, _
) ->
1681 let ready = layoutready layout in
1685 state.layout <- layout;
1686 state.throttle
<- None
;
1687 G.postRedisplay "throttle";
1694 dolog "Inconsistent tiling state";
1695 logcurrently state.currently
;
1702 Scanf.sscanf args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1704 dolog "error processing 'pdim' %S: %s"
1705 cmds
(Printexc.to_string exn
);
1708 state.uioh#infochanged Pdim
;
1709 state.pdims
<- pdim :: state.pdims
1712 let (l, n, t
, h, pos
) =
1714 Scanf.sscanf args
"%u %u %d %u %n"
1715 (fun l n t
h pos
-> l, n, t
, h, pos
)
1717 dolog "error processing 'o' %S: %s"
1718 cmds
(Printexc.to_string exn
);
1721 let s = String.sub args pos
(String.length args
- pos
) in
1722 let outline = (s, l, (n, float t
/. float h)) in
1723 begin match state.currently
with
1724 | Outlining outlines
->
1725 state.currently
<- Outlining
(outline :: outlines
)
1727 state.currently
<- Outlining
[outline]
1729 dolog "invalid outlining state";
1730 logcurrently currently
1734 state.docinfo
<- (1, args
) :: state.docinfo
1737 state.uioh#infochanged Docinfo
;
1738 state.docinfo
<- List.rev
state.docinfo
1741 dolog "unknown cmd `%S'" cmds
1745 if state.deadline
== nan
then state.deadline
<- now ();
1746 let rec loop delay
=
1749 then max
0.0 (state.deadline
-. now ())
1752 let r, _
, _
= Unix.select
[state.csock
; state.errfd
] [] [] timeout in
1755 begin match state.autoscroll
with
1756 | Some step
when step
!= 0 ->
1757 let y = state.y + step
in
1761 else if y >= state.maxy then 0 else y
1764 if state.mode
= View
1765 then state.text <- "";
1766 state.deadline
<- state.deadline
+. 0.005;
1769 state.deadline
<- state.deadline
+. delay
;
1773 let rec checkfds c = function
1775 | fd
:: rest
when fd
= state.csock
->
1776 let cmd = readcmd state.csock
in
1779 | fd
:: rest
when fd
= state.errfd
->
1780 let s = String.create
80 in
1781 let n = Unix.read fd
s 0 80 in
1782 if conf.redirectstderr
1784 Buffer.add_substring
state.errmsgs
s 0 n;
1785 state.newerrmsgs
<- true;
1786 Glut.postRedisplay ();
1789 prerr_string
(String.sub
s 0 n);
1795 failwith
"me? fail english? that's unpossible!"
1805 let action = function
1806 | HCprev
-> cbget cb ~
-1
1807 | HCnext
-> cbget cb
1
1808 | HCfirst
-> cbget cb ~
-(cb
.rc)
1809 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1810 and cancel
() = cb
.rc <- rc
1814 let search pattern forward
=
1815 if String.length pattern
> 0
1818 match state.layout with
1821 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1824 let b = makecmd "search"
1825 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
1827 Buffer.add_char
b '
,'
;
1828 Buffer.add_string
b pattern
;
1829 Buffer.add_char
b '
\000'
;
1832 writecmd state.csock
cmd;
1835 let intentry text key =
1836 let c = Char.unsafe_chr
key in
1839 let text = addchar text c in
1843 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
1847 let textentry text key =
1848 let c = Char.unsafe_chr
key in
1850 | _
when key >= 32 && key < 127 ->
1851 let text = addchar text c in
1855 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
1859 let reqlayout angle proportional
=
1860 match state.throttle
with
1862 if state.invalidated
= 0 then state.anchor <- getanchor ();
1863 conf.angle
<- angle
mod 360;
1864 conf.proportional
<- proportional
;
1866 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
1870 let settrim trimmargins trimfuzz
=
1871 if state.invalidated
= 0 then state.anchor <- getanchor ();
1872 conf.trimmargins
<- trimmargins
;
1873 conf.trimfuzz
<- trimfuzz
;
1874 let x0, y0
, x1
, y1
= trimfuzz
in
1877 `
b conf.trimmargins
;
1883 Hashtbl.iter
(fun _ opaque
->
1884 wcmd "freepage" [`
s opaque
];
1886 Hashtbl.clear
state.pagemap
;
1890 match state.throttle
with
1892 let zoom = max
0.01 zoom in
1893 if zoom <> conf.zoom
1895 state.prevzoom
<- conf.zoom;
1898 then (state.x <- 0; 0.0)
1899 else float state.x /. float state.w
1902 reshape conf.winw
conf.winh
;
1905 let x = relx *. float state.w in
1906 state.x <- truncate
x;
1908 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
1911 | Some
(layout, y, started
) ->
1913 match conf.maxwait
with
1917 let dt = now () -. started
in
1925 let enterbirdseye () =
1926 let zoom = float conf.thumbw
/. float conf.winw
in
1927 let birdseyepageno =
1928 let cy = conf.winh
/ 2 in
1932 let rec fold best
= function
1935 let d = cy - (l.pagedispy
+ l.pagevh/2)
1936 and dbest
= cy - (best
.pagedispy
+ best
.pagevh/2) in
1937 if abs
d < abs dbest
1944 state.mode
<- Birdseye
(
1945 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
1948 conf.presentation <- false;
1949 conf.interpagespace <- 10;
1950 conf.hlinks
<- false;
1952 state.mstate
<- Mnone
;
1953 conf.maxwait
<- None
;
1954 Glut.setCursor
Glut.CURSOR_INHERIT
;
1957 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1962 reshape conf.winw
conf.winh
;
1965 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
1967 conf.zoom <- c.zoom;
1968 conf.presentation <- c.presentation;
1969 conf.interpagespace <- c.interpagespace;
1970 conf.maxwait
<- c.maxwait
;
1971 conf.hlinks
<- c.hlinks
;
1975 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1978 reshape conf.winw
conf.winh
;
1979 state.anchor <- if goback
then anchor else (pageno, 0.0);
1982 let togglebirdseye () =
1983 match state.mode
with
1984 | Birdseye vals
-> leavebirdseye vals
true
1985 | View
-> enterbirdseye ()
1989 let upbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
1990 let pageno = max
0 (pageno - 1) in
1991 let rec loop = function
1992 | [] -> gotopage1 pageno 0
1993 | l :: _
when l.pageno = pageno ->
1994 if l.pagedispy
>= 0 && l.pagey = 0
1995 then G.postRedisplay "upbirdseye"
1996 else gotopage1 pageno 0
1997 | _
:: rest
-> loop rest
2000 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2003 let downbirdseye (conf, leftx
, pageno, hooverpageno
, anchor) =
2004 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
2005 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2006 let rec loop = function
2008 let y, h = getpageyh pageno in
2009 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2011 | l :: _
when l.pageno = pageno ->
2012 if l.pagevh != l.pageh
2013 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2014 else G.postRedisplay "downbirdseye"
2015 | _
:: rest
-> loop rest
2020 let optentry mode _
key =
2021 let btos b = if b then "on" else "off" in
2022 let c = Char.unsafe_chr
key in
2026 try conf.scrollstep
<- int_of_string
s with exc
->
2027 state.text <- Printf.sprintf
"bad integer `%s': %s"
2028 s (Printexc.to_string exc
)
2030 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2035 conf.autoscrollstep
<- int_of_string
s;
2036 if state.autoscroll
<> None
2037 then state.autoscroll
<- Some
conf.autoscrollstep
2039 state.text <- Printf.sprintf
"bad integer `%s': %s"
2040 s (Printexc.to_string exc
)
2042 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2047 let zoom = float (int_of_string
s) /. 100.0 in
2050 state.text <- Printf.sprintf
"bad integer `%s': %s"
2051 s (Printexc.to_string exc
)
2053 TEswitch
("zoom: ", "", None
, intentry, ondone)
2058 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2060 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2061 begin match mode
with
2063 leavebirdseye beye
false;
2068 state.text <- Printf.sprintf
"bad integer `%s': %s"
2069 s (Printexc.to_string exc
)
2071 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2076 Some
(int_of_string
s)
2078 state.text <- Printf.sprintf
"bad integer `%s': %s"
2079 s (Printexc.to_string exc
);
2082 | Some angle
-> reqlayout angle
conf.proportional
2085 TEswitch
("rotation: ", "", None
, intentry, ondone)
2088 conf.icase
<- not
conf.icase
;
2089 TEdone
("case insensitive search " ^
(btos conf.icase
))
2092 conf.preload <- not
conf.preload;
2094 TEdone
("preload " ^
(btos conf.preload))
2097 conf.verbose
<- not
conf.verbose
;
2098 TEdone
("verbose " ^
(btos conf.verbose
))
2101 conf.debug
<- not
conf.debug
;
2102 TEdone
("debug " ^
(btos conf.debug
))
2105 conf.maxhfit
<- not
conf.maxhfit
;
2107 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2108 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2111 conf.crophack
<- not
conf.crophack
;
2112 TEdone
("crophack " ^
btos conf.crophack
)
2116 match conf.maxwait
with
2118 conf.maxwait
<- Some infinity
;
2119 "always wait for page to complete"
2121 conf.maxwait
<- None
;
2122 "show placeholder if page is not ready"
2127 conf.underinfo
<- not
conf.underinfo
;
2128 TEdone
("underinfo " ^
btos conf.underinfo
)
2131 conf.savebmarks
<- not
conf.savebmarks
;
2132 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2138 match state.layout with
2143 conf.interpagespace <- int_of_string
s;
2144 state.maxy <- calcheight ();
2145 let y = getpagey pageno in
2148 state.text <- Printf.sprintf
"bad integer `%s': %s"
2149 s (Printexc.to_string exc
)
2151 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2154 reqlayout conf.angle
(not
conf.proportional
);
2155 TEdone
("proportional display " ^
btos conf.proportional
)
2158 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2159 TEdone
("trim margins " ^
btos conf.trimmargins
)
2162 conf.invert
<- not
conf.invert
;
2163 TEdone
("invert colors " ^
btos conf.invert
)
2166 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2170 class type lvsource
= object
2171 method getitemcount
: int
2172 method getitem
: int -> (string * int)
2173 method hasaction
: int -> bool
2182 method getactive
: int
2183 method getfirst
: int
2184 method getqsearch
: string
2185 method setqsearch
: string -> unit
2189 class virtual lvsourcebase
= object
2190 val mutable m_active
= 0
2191 val mutable m_first
= 0
2192 val mutable m_qsearch
= ""
2193 val mutable m_pan
= 0
2194 method getactive
= m_active
2195 method getfirst
= m_first
2196 method getqsearch
= m_qsearch
2197 method getpan
= m_pan
2198 method setqsearch
s = m_qsearch
<- s
2201 let textentryspecial key = function
2202 | ((c, _
, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2205 | Glut.KEY_UP
-> action HCprev
2206 | Glut.KEY_DOWN
-> action HCnext
2207 | Glut.KEY_HOME
-> action HCfirst
2208 | Glut.KEY_END
-> action HClast
2211 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2212 G.postRedisplay "special textentry";
2216 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2218 state.mode
<- Textentry
(te
, onleave
);
2221 G.postRedisplay "textentrykeyboard enttext";
2223 match Char.unsafe_chr
key with
2224 | '
\008'
-> (* backspace *)
2225 let len = String.length
text in
2229 G.postRedisplay "textentrykeyboard after cancel";
2232 let s = String.sub
text 0 (len - 1) in
2233 enttext (c, s, opthist
, onkey
, ondone)
2239 G.postRedisplay "textentrykeyboard after confirm"
2241 | '
\007'
(* ctrl-g *)
2242 | '
\027'
-> (* escape *)
2243 if String.length
text = 0
2245 begin match opthist
with
2247 | Some
(_
, onhistcancel
) -> onhistcancel
()
2251 G.postRedisplay "textentrykeyboard after cancel2"
2254 enttext (c, "", opthist
, onkey
, ondone)
2257 | '
\127'
-> () (* delete *)
2260 begin match onkey
text key with
2264 G.postRedisplay "textentrykeyboard after confirm2";
2267 enttext (c, text, opthist
, onkey
, ondone);
2272 G.postRedisplay "textentrykeyboard after cancel3"
2275 state.mode
<- Textentry
(te
, onleave
);
2276 G.postRedisplay "textentrykeyboard switch";
2280 let firstof first active
=
2281 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2282 then max
0 (active
- (fstate.maxrows
/2))
2286 let calcfirst first active
=
2289 let rows = active
- first
in
2290 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2294 let coe s = (s :> uioh
);;
2296 class listview ~
(source
:lvsource
) ~trusted
=
2298 val m_pan
= source#getpan
2299 val m_first
= source#getfirst
2300 val m_active
= source#getactive
2301 val m_qsearch
= source#getqsearch
2302 val m_prev_uioh
= state.uioh
2304 method private elemunder
y =
2305 let n = y / (fstate.fontsize
+1) in
2306 if m_first
+ n < source#getitemcount
2308 if source#hasaction
(m_first
+ n)
2309 then Some
(m_first
+ n)
2316 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2317 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2318 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2319 GlDraw.color
(1., 1., 1.);
2320 Gl.enable `texture_2d
;
2321 let fs = fstate.fontsize
in
2323 let ww = fstate.wwidth
in
2324 let tabw = 30.0*.ww in
2326 if (row - m_first
) * nfs > conf.winh
2329 if row >= 0 && row < source#getitemcount
2331 let (s, level
) = source#getitem
row in
2332 let y = (row - m_first
) * nfs in
2333 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2336 Gl.disable `texture_2d
;
2337 GlDraw.polygon_mode `both `line
;
2338 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2339 GlDraw.rect (1., float (y + 1))
2340 (float (conf.winw
- 1), float (y + fs + 3));
2341 GlDraw.polygon_mode `both `fill
;
2342 GlDraw.color
(1., 1., 1.);
2343 Gl.enable `texture_2d
;
2346 let drawtabularstring s =
2347 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2350 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2353 let len = String.length
s - tabpos - 1 in
2354 let s1 = String.sub
s 0 tabpos
2355 and s2
= String.sub
s (tabpos + 1) len in
2356 let nx = drawstr x s1 in
2358 let x = x +. (max
tabw sw) in
2365 let _ = drawtabularstring s in
2372 Gl.disable `texture_2d
;
2374 method updownlevel incr
=
2375 let len = source#getitemcount
in
2376 let _, curlevel
= source#getitem m_active
in
2378 if i
= len then i
-1 else if i
= -1 then 0 else
2379 let _, l = source#getitem i
in
2380 if l != curlevel
then i
else flow (i
+incr
)
2382 let active = flow m_active
in
2383 let first = calcfirst m_first
active in
2384 G.postRedisplay "special outline updownlevel";
2385 {< m_active
= active; m_first
= first >}
2387 method private key1
key =
2388 let set active first qsearch
=
2389 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2391 let search active pattern incr
=
2394 if n >= 0 && n < source#getitemcount
2396 let s, _ = source#getitem
n in
2398 (try ignore
(Str.search_forward
re s 0); true
2399 with Not_found
-> false)
2401 else loop (n + incr
)
2408 let re = Str.regexp_case_fold pattern
in
2415 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2416 let incr = if key = 18 then -1 else 1 in
2418 match search (m_active
+ incr) m_qsearch
incr with
2420 state.text <- m_qsearch ^
" [not found]";
2423 state.text <- m_qsearch
;
2424 active, firstof m_first
active
2426 G.postRedisplay "listview ctrl-r/s";
2427 set active first m_qsearch
;
2429 | 8 -> (* backspace *)
2430 let len = String.length m_qsearch
in
2437 G.postRedisplay "listview empty qsearch";
2438 set m_active m_first
"";
2441 let qsearch = String.sub m_qsearch
0 (len - 1) in
2443 match search m_active
qsearch ~
-1 with
2445 state.text <- qsearch ^
" [not found]";
2448 state.text <- qsearch;
2449 active, firstof m_first
active
2451 G.postRedisplay "listview backspace qsearch";
2452 set active first qsearch
2455 | _ when key >= 32 && key < 127 ->
2456 let pattern = addchar m_qsearch
(Char.chr
key) in
2458 match search m_active
pattern 1 with
2460 state.text <- pattern ^
" [not found]";
2463 state.text <- pattern;
2464 active, firstof m_first
active
2466 G.postRedisplay "listview qsearch add";
2467 set active first pattern;
2469 | 27 -> (* escape *)
2471 if String.length m_qsearch
= 0
2473 G.postRedisplay "list view escape";
2476 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2478 | None
-> m_prev_uioh
2483 G.postRedisplay "list view kill qsearch";
2484 source#setqsearch
"";
2485 coe {< m_qsearch
= "" >}
2490 let self = {< m_qsearch
= "" >} in
2491 source#setqsearch
"";
2493 G.postRedisplay "listview enter";
2494 if m_active
>= 0 && m_active
< source#getitemcount
2496 source#exit
(coe self) false m_active m_first m_pan
"";
2499 source#exit
(coe self) true m_active m_first m_pan
"";
2502 begin match opt with
2503 | None
-> m_prev_uioh
2507 | 127 -> (* delete *)
2510 | _ -> dolog "unknown key %d" key; coe self
2512 method private special1
key =
2513 let itemcount = source#getitemcount
in
2514 let find start
incr =
2516 if i
= -1 || i
= itemcount
2519 if source#hasaction i
2521 else find (i
+ incr)
2526 let set active first =
2527 let first = bound first 0 (itemcount - fstate.maxrows
) in
2529 coe {< m_active
= active; m_first
= first >}
2532 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2534 let incr1 = if incr > 0 then 1 else -1 in
2535 if isvisible m_first m_active
2538 let next = m_active
+ incr in
2540 if next < 0 || next >= itemcount
2542 else find next incr1
2544 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2550 let first = m_first
+ incr in
2551 let first = bound first 0 (itemcount - 1) in
2553 let next = m_active
+ incr in
2554 let next = bound next 0 (itemcount - 1) in
2557 let active = if next = -1 then m_active
else next in
2560 let first = min
next m_first
in
2563 let first = m_first
+ incr in
2564 let first = bound first 0 (itemcount - 1) in
2566 let next = m_active
+ incr in
2567 let next = bound next 0 (itemcount - 1) in
2568 let next = find next incr1 in
2569 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2575 G.postRedisplay "listview navigate";
2578 begin match key with
2579 | Glut.KEY_UP
-> navigate ~
-1
2580 | Glut.KEY_DOWN
-> navigate 1
2581 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2582 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2586 G.postRedisplay "listview right";
2587 coe {< m_pan
= m_pan
- 1 >}
2591 G.postRedisplay "listview left";
2592 coe {< m_pan
= m_pan
+ 1 >}
2595 let active = find 0 1 in
2596 G.postRedisplay "listview home";
2600 let first = max
0 (itemcount - fstate.maxrows
) in
2601 let active = find (itemcount - 1) ~
-1 in
2602 G.postRedisplay "listview end";
2609 match state.mode
with
2610 | Textentry te
-> textentrykeyboard key te
; coe self
2611 | _ -> self#key1
key
2613 method special
key =
2614 match state.mode
with
2615 | Textentry te
-> textentryspecial key te
; coe self
2616 | _ -> self#special1
key
2618 method button button bstate
_ y =
2621 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2622 begin match self#elemunder
y with
2624 G.postRedisplay "listview click";
2626 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
2630 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2631 let len = source#getitemcount
in
2633 if m_first
+ fstate.maxrows
>= len
2637 let first = m_first
+ (if n == 3 then -1 else 1) in
2638 bound first 0 (len - 1)
2640 G.postRedisplay "listview wheel";
2641 Some
(coe {< m_first
= first >})
2646 | None
-> m_prev_uioh
2649 method motion
_ _ = coe self
2651 method pmotion
_ y =
2653 match self#elemunder
y with
2654 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
2655 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
2659 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
2664 method infochanged
_ = ()
2667 class outlinelistview ~source
=
2669 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
2673 | 14 -> (* ctrl-n *)
2674 source#narrow m_qsearch
;
2675 G.postRedisplay "outline ctrl-n";
2676 coe {< m_first
= 0; m_active
= 0 >}
2678 | 21 -> (* ctrl-u *)
2680 G.postRedisplay "outline ctrl-u";
2681 coe {< m_first
= 0; m_active
= 0 >}
2683 | 12 -> (* ctrl-l *)
2684 let first = m_active
- (fstate.maxrows
/ 2) in
2685 G.postRedisplay "outline ctrl-l";
2686 coe {< m_first
= first >}
2688 | 127 -> (* delete *)
2689 source#remove m_active
;
2690 G.postRedisplay "outline delete";
2691 let active = max
0 (m_active
-1) in
2692 coe {< m_first
= firstof m_first
active;
2693 m_active
= active >}
2695 | key -> super#
key key
2697 method special
key =
2698 let calcfirst first active =
2701 let rows = active - first in
2702 if rows > fstate.maxrows
then active - fstate.maxrows
else first
2706 let active = m_active
+ incr in
2707 let active = bound active 0 (source#getitemcount
- 1) in
2708 let first = calcfirst m_first
active in
2709 G.postRedisplay "special outline navigate";
2710 coe {< m_active
= active; m_first
= first >}
2713 | Glut.KEY_UP
-> navigate ~
-1
2714 | Glut.KEY_DOWN
-> navigate 1
2715 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2716 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2720 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2722 G.postRedisplay "special outline right";
2723 {< m_pan
= m_pan
+ 1 >}
2725 else self#updownlevel
1
2731 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2733 G.postRedisplay "special outline left";
2734 {< m_pan
= m_pan
- 1 >}
2736 else self#updownlevel ~
-1
2741 G.postRedisplay "special outline home";
2742 coe {< m_first
= 0; m_active
= 0 >}
2745 let active = source#getitemcount
- 1 in
2746 let first = max
0 (active - fstate.maxrows
) in
2747 G.postRedisplay "special outline end";
2748 coe {< m_active
= active; m_first
= first >}
2750 | _ -> super#special
key
2753 let outlinesource usebookmarks
=
2756 inherit lvsourcebase
2757 val mutable m_items
= empty
2758 val mutable m_orig_items
= empty
2759 val mutable m_prev_items
= empty
2760 val mutable m_narrow_pattern
= ""
2761 val mutable m_hadremovals
= false
2763 method getitemcount
=
2764 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
2767 if n == Array.length m_items
&& m_hadremovals
2769 ("[Confirm removal]", 0)
2771 let s, n, _ = m_items
.(n) in
2774 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
2775 ignore
(uioh
, first, pan
, qsearch);
2776 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
2778 if String.length m_narrow_pattern
= 0
2784 if not
confrimremoval
2786 let _, _, anchor = m_items
.(active) in
2791 state.bookmarks
<- Array.to_list m_items
;
2792 m_orig_items
<- m_items
;
2795 else m_items
<- items;
2798 method hasaction
_ = true
2801 if Array.length m_items
!= Array.length m_orig_items
2802 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
2805 method narrow
pattern =
2806 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
2810 let rec loop accu n =
2813 m_narrow_pattern
<- pattern;
2814 m_items
<- Array.of_list
accu
2817 let (s, _, _) as o = m_items
.(n) in
2819 if (try ignore
(Str.search_forward
re s 0); true
2820 with Not_found
-> false)
2826 loop [] (Array.length m_items
- 1)
2831 then Array.of_list
state.bookmarks
2834 m_items
<- m_orig_items
2839 if m
>= 0 && m
< Array.length m_items
2841 m_hadremovals
<- true;
2842 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
2843 let n = if n >= m
then n+1 else n in
2848 method reset
pageno items =
2849 m_hadremovals
<- false;
2850 if m_orig_items
== empty || m_prev_items
!= items
2852 m_orig_items
<- items;
2853 if String.length m_narrow_pattern
= 0
2854 then m_items
<- items;
2856 m_prev_items
<- items;
2858 let rec loop n best bestd
=
2859 if n = Array.length m_items
2862 let (_, _, (outlinepageno
, _)) = m_items
.(n) in
2863 let d = abs
(outlinepageno
- pageno) in
2866 else loop (n+1) best bestd
2871 m_first
<- firstof m_first
active
2875 let enterselector usebookmarks
=
2876 let source = outlinesource usebookmarks
in
2880 then Array.of_list
state.bookmarks
2883 if Array.length
outlines = 0
2885 showtext ' ' errmsg
;
2888 state.text <- source#greetmsg
;
2889 Glut.setCursor
Glut.CURSOR_INHERIT
;
2891 match state.layout with
2893 | {pageno=pageno} :: _ -> pageno
2895 source#reset
pageno outlines;
2896 state.uioh
<- coe (new outlinelistview ~
source);
2897 G.postRedisplay "enter selector";
2901 let enteroutlinemode =
2902 let f = enterselector false in
2903 fun ()-> f "Document has no outline";
2906 let enterbookmarkmode =
2907 let f = enterselector true in
2908 fun () -> f "Document has no bookmarks (yet)";
2911 let color_of_string s =
2912 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
2913 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
2917 let color_to_string (r, g
, b) =
2918 let r = truncate
(r *. 256.0)
2919 and g
= truncate
(g
*. 256.0)
2920 and b = truncate
(b *. 256.0) in
2921 Printf.sprintf
"%d/%d/%d" r g
b
2924 let irect_of_string s =
2925 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0,y0
,x1
,y1
))
2928 let irect_to_string (x0,y0
,x1
,y1
) =
2929 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
2932 let makecheckers () =
2933 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
2935 converted by Issac Trotts. July 25, 2002 *)
2936 let image_height = 64
2937 and image_width
= 64 in
2941 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
2943 for i
= 0 to image_width
- 1 do
2944 for j
= 0 to image_height - 1 do
2945 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
2946 (if (i
land 8 ) lxor (j
land 8) = 0
2947 then [|255;255;255|] else [|200;200;200|])
2952 let image = make_image () in
2953 let id = GlTex.gen_texture
() in
2954 GlTex.bind_texture `texture_2d
id;
2955 GlPix.store
(`unpack_alignment
1);
2956 GlTex.image2d
image;
2957 List.iter
(GlTex.parameter ~target
:`texture_2d
)
2960 `mag_filter `nearest
;
2961 `min_filter `nearest
];
2965 let setcheckers enabled
=
2966 match state.texid
with
2968 if enabled
then state.texid
<- Some
(makecheckers ())
2973 GlTex.delete_texture texid
;
2974 state.texid
<- None
;
2978 let int_of_string_with_suffix s =
2979 let l = String.length
s in
2983 let suffix = Char.lowercase
s.[l-1] in
2985 | 'k'
-> String.sub
s 0 (l-1), 10
2986 | 'm'
-> String.sub
s 0 (l-1), 20
2987 | 'g'
-> String.sub
s 0 (l-1), 30
2991 let n = int_of_string
s1 in
2992 let m = n lsl shift
in
2994 then raise
(Failure
"value too large")
2998 let string_with_suffix_of_int n =
3006 if n land ((1 lsl 20) - 1) = 0
3009 if n land ((1 lsl 10) - 1) = 0
3016 let h = n mod 1000 in
3019 then string_of_int
h ^
s
3021 let s = Printf.sprintf
"_%03d%s" h s in
3028 let describe_location () =
3030 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3032 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3033 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3037 else (100. *. (float state.y /. float maxy))
3041 Printf.sprintf
"page %d of %d [%.2f%%]"
3042 (fn+1) state.pagecount
percent
3045 "pages %d-%d of %d [%.2f%%]"
3046 (fn+1) (ln
+1) state.pagecount
percent
3050 let btos b = if b then "\xe2\x88\x9a" else "" in
3051 let showextended = ref false in
3052 let leave mode
= function
3053 | Confirm
-> state.mode
<- mode
3054 | Cancel
-> state.mode
<- mode
in
3057 val mutable m_first_time
= true
3058 val mutable m_l
= []
3059 val mutable m_a
= [||]
3060 val mutable m_prev_uioh
= nouioh
3061 val mutable m_prev_mode
= View
3063 inherit lvsourcebase
3065 method reset prev_mode prev_uioh
=
3066 m_a
<- Array.of_list
(List.rev m_l
);
3068 m_prev_mode
<- prev_mode
;
3069 m_prev_uioh
<- prev_uioh
;
3073 if n >= Array.length m_a
3077 | _, _, _, Action
_ -> m_active
<- n
3081 m_first_time
<- false;
3084 method int name get
set =
3086 (name
, `
int get
, 1, Action
(
3089 try set (int_of_string
s)
3091 state.text <- Printf.sprintf
"bad integer `%s': %s"
3092 s (Printexc.to_string exn
)
3095 let te = name ^
": ", "", None
, intentry, ondone in
3096 state.mode
<- Textentry
(te, leave m_prev_mode
);
3100 method int_with_suffix name get
set =
3102 (name
, `intws get
, 1, Action
(
3105 try set (int_of_string_with_suffix s)
3107 state.text <- Printf.sprintf
"bad integer `%s': %s"
3108 s (Printexc.to_string exn
)
3112 name ^
": ", "", None
, intentry_with_suffix, ondone
3114 state.mode
<- Textentry
(te, leave m_prev_mode
);
3118 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3120 (name
, `
bool (btos, get
), offset
, Action
(
3127 method color name get
set =
3129 (name
, `color get
, 1, Action
(
3131 let invalid = (nan
, nan
, nan
) in
3134 try color_of_string s
3136 state.text <- Printf.sprintf
"bad color `%s': %s"
3137 s (Printexc.to_string exn
);
3143 let te = name ^
": ", "", None
, textentry, ondone in
3144 state.text <- color_to_string (get
());
3145 state.mode
<- Textentry
(te, leave m_prev_mode
);
3149 method string name get
set =
3151 (name
, `
string get
, 1, Action
(
3153 let ondone s = set s in
3154 let te = name ^
": ", "", None
, textentry, ondone in
3155 state.mode
<- Textentry
(te, leave m_prev_mode
);
3159 method colorspace name get
set =
3161 (name
, `
string get
, 1, Action
(
3164 let vals = [| "rgb"; "bgr"; "gray" |] in
3166 inherit lvsourcebase
3169 m_active
<- int_of_colorspace conf.colorspace
;
3172 method getitemcount
= Array.length
vals
3173 method getitem
n = (vals.(n), 0)
3174 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3175 ignore
(uioh
, first, pan
, qsearch);
3176 if not cancel
then set active;
3178 method hasaction
_ = true
3182 coe (new listview ~
source ~trusted
:true)
3185 method caption
s offset
=
3186 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3188 method caption2
s f offset
=
3189 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3191 method getitemcount
= Array.length m_a
3194 let tostr = function
3195 | `
int f -> string_of_int
(f ())
3196 | `intws
f -> string_with_suffix_of_int (f ())
3198 | `color
f -> color_to_string (f ())
3199 | `
bool (btos, f) -> btos (f ())
3202 let name, t
, offset
, _ = m_a
.(n) in
3203 ((let s = tostr t
in
3204 if String.length
s > 0
3205 then Printf.sprintf
"%s\t%s" name s
3209 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3213 m_qsearch
<- qsearch;
3215 match m_a
.(active) with
3216 | _, _, _, Action
f -> f uioh
3228 method hasaction
n =
3230 | _, _, _, Action
_ -> true
3234 let rec fillsrc prevmode prevuioh
=
3235 let sep () = src#caption
"" 0 in
3236 let colorp name get
set =
3238 (fun () -> color_to_string (get
()))
3241 let c = color_of_string v in
3244 state.text <- Printf.sprintf
"bad color `%s': %s"
3245 v (Printexc.to_string exn
);
3248 let oldmode = state.mode
in
3249 let birdseye = isbirdseye state.mode
in
3251 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3253 src#
bool "presentation mode"
3254 (fun () -> conf.presentation)
3256 conf.presentation <- v;
3257 state.anchor <- getanchor ();
3260 src#
bool "ignore case in searches"
3261 (fun () -> conf.icase
)
3262 (fun v -> conf.icase
<- v);
3265 (fun () -> conf.preload)
3266 (fun v -> conf.preload <- v);
3268 src#
bool "highlight links"
3269 (fun () -> conf.hlinks
)
3270 (fun v -> conf.hlinks
<- v);
3272 src#
bool "under info"
3273 (fun () -> conf.underinfo
)
3274 (fun v -> conf.underinfo
<- v);
3276 src#
bool "persistent bookmarks"
3277 (fun () -> conf.savebmarks
)
3278 (fun v -> conf.savebmarks
<- v);
3280 src#
bool "proportional display"
3281 (fun () -> conf.proportional
)
3282 (fun v -> reqlayout conf.angle
v);
3284 src#
bool "trim margins"
3285 (fun () -> conf.trimmargins
)
3286 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3288 src#
bool "persistent location"
3289 (fun () -> conf.jumpback
)
3290 (fun v -> conf.jumpback
<- v);
3293 src#
int "vertical margin"
3294 (fun () -> conf.interpagespace)
3296 conf.interpagespace <- n;
3298 match state.layout with
3303 state.maxy <- calcheight ();
3304 let y = getpagey pageno in
3309 (fun () -> conf.pagebias
)
3310 (fun v -> conf.pagebias
<- v);
3312 src#
int "scroll step"
3313 (fun () -> conf.scrollstep
)
3314 (fun n -> conf.scrollstep
<- n);
3316 src#
int "auto scroll step"
3318 match state.autoscroll
with
3320 | _ -> conf.autoscrollstep
)
3322 if state.autoscroll
<> None
3323 then state.autoscroll
<- Some
n;
3324 conf.autoscrollstep
<- n);
3327 (fun () -> truncate
(conf.zoom *. 100.))
3328 (fun v -> setzoom ((float v) /. 100.));
3331 (fun () -> conf.angle
)
3332 (fun v -> reqlayout v conf.proportional
);
3334 src#
int "scroll bar width"
3335 (fun () -> state.scrollw
)
3339 reshape conf.winw
conf.winh
;
3342 src#
int "scroll handle height"
3343 (fun () -> conf.scrollh
)
3344 (fun v -> conf.scrollh
<- v;);
3346 src#
int "thumbnail width"
3347 (fun () -> conf.thumbw
)
3349 conf.thumbw
<- min
4096 v;
3352 leavebirdseye beye
false;
3358 src#caption
"Presentation mode" 0;
3359 src#
bool "scrollbar visible"
3360 (fun () -> conf.scrollbarinpm
)
3362 if v != conf.scrollbarinpm
3364 conf.scrollbarinpm
<- v;
3365 if conf.presentation
3367 state.scrollw
<- if v then conf.scrollbw
else 0;
3368 reshape conf.winw
conf.winh
;
3374 src#caption
"Pixmap cache" 0;
3375 src#int_with_suffix
"size (advisory)"
3376 (fun () -> conf.memlimit
)
3377 (fun v -> conf.memlimit
<- v);
3380 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3381 (string_with_suffix_of_int state.memused
)
3382 (Hashtbl.length
state.tilemap
)) 1;
3385 src#caption
"Layout" 0;
3386 src#caption2
"Dimension"
3388 Printf.sprintf
"%dx%d (virtual %dx%d)"
3394 src#caption2
"Position" (fun () ->
3395 Printf.sprintf
"%dx%d" state.x state.y
3398 src#caption2
"Visible" (fun () -> describe_location ()) 1
3402 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3403 "Save these parameters as global defaults at exit"
3404 (fun () -> conf.bedefault
)
3405 (fun v -> conf.bedefault
<- v)
3409 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3410 src#
bool ~offset
:0 ~
btos "Extended parameters"
3411 (fun () -> !showextended)
3412 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3416 (fun () -> conf.checkers
)
3417 (fun v -> conf.checkers
<- v; setcheckers v);
3419 (fun () -> conf.verbose
)
3420 (fun v -> conf.verbose
<- v);
3421 src#
bool "invert colors"
3422 (fun () -> conf.invert
)
3423 (fun v -> conf.invert
<- v);
3425 (fun () -> conf.maxhfit
)
3426 (fun v -> conf.maxhfit
<- v);
3427 src#
bool "redirect stderr"
3428 (fun () -> conf.redirectstderr)
3429 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3430 src#
string "uri launcher"
3431 (fun () -> conf.urilauncher
)
3432 (fun v -> conf.urilauncher
<- v);
3433 src#
string "tile size"
3434 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3437 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3438 conf.tileh
<- max
64 w;
3439 conf.tilew
<- max
64 h;
3442 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3443 v (Printexc.to_string exn
));
3444 src#
int "texture count"
3445 (fun () -> conf.texcount
)
3448 wcmd "texcount" [`i
conf.texcount
];
3450 src#
int "slice height"
3451 (fun () -> conf.sliceheight
)
3453 conf.sliceheight
<- v;
3454 wcmd "sliceh" [`i
conf.sliceheight
];
3456 src#
int "anti-aliasing level"
3457 (fun () -> conf.aalevel
)
3459 conf.aalevel
<- bound v 0 8;
3460 state.anchor <- getanchor ();
3461 opendoc state.path
state.password
;
3463 src#
int "ui font size"
3464 (fun () -> fstate.fontsize
)
3465 (fun v -> setfontsize (bound v 5 100));
3466 colorp "background color"
3467 (fun () -> conf.bgcolor
)
3468 (fun v -> conf.bgcolor
<- v);
3469 src#
bool "crop hack"
3470 (fun () -> conf.crophack
)
3471 (fun v -> conf.crophack
<- v);
3472 src#
string "trim fuzz"
3473 (fun () -> irect_to_string conf.trimfuzz
)
3476 conf.trimfuzz
<- irect_of_string v;
3478 then settrim true conf.trimfuzz
;
3480 state.text <- Printf.sprintf
"bad irect `%s': %s"
3481 v (Printexc.to_string exn
)
3483 src#
string "throttle"
3485 match conf.maxwait
with
3486 | None
-> "show place holder if page is not ready"
3489 then "wait for page to fully render"
3491 "wait " ^ string_of_float
time
3492 ^
" seconds before showing placeholder"
3496 let f = float_of_string
v in
3498 then conf.maxwait
<- None
3499 else conf.maxwait
<- Some
f
3501 state.text <- Printf.sprintf
"bad time `%s': %s"
3502 v (Printexc.to_string exn
)
3504 src#colorspace
"color space"
3505 (fun () -> colorspace_to_string conf.colorspace
)
3507 conf.colorspace
<- colorspace_of_int v;
3514 src#caption
"Document" 0;
3515 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
3519 src#caption
"Trimmed margins" 0;
3520 src#caption2
"Dimensions"
3521 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
3524 src#reset prevmode prevuioh
;
3528 let prevmode = state.mode
3529 and prevuioh
= state.uioh in
3530 fillsrc prevmode prevuioh
;
3531 let source = (src :> lvsource
) in
3532 state.uioh <- coe (object (self)
3533 inherit listview ~
source ~trusted
:true as super
3534 val mutable m_prevmemused
= 0
3535 method infochanged
= function
3537 if m_prevmemused
!= state.memused
3539 m_prevmemused
<- state.memused
;
3540 G.postRedisplay "memusedchanged";
3542 | Pdim
-> G.postRedisplay "pdimchanged"
3543 | Docinfo
-> fillsrc prevmode prevuioh
3545 method special
key =
3546 if Glut.getModifiers
() land Glut.active_ctrl
= 0
3549 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
3550 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
3551 | _ -> super#special
key
3552 else super#special
key
3554 G.postRedisplay "info";
3560 inherit lvsourcebase
3561 method getitemcount
= Array.length
state.help
3563 let s, n, _ = state.help
.(n) in
3566 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3570 m_qsearch
<- qsearch;
3571 match state.help
.(active) with
3572 | _, _, Action
f -> Some
(f uioh)
3582 method hasaction
n =
3583 match state.help
.(n) with
3584 | _, _, Action
_ -> true
3591 state.uioh <- coe (new listview ~
source ~trusted
:true);
3592 G.postRedisplay "help";
3597 let re = Str.regexp
"[\r\n]" in
3599 inherit lvsourcebase
3600 val mutable m_items
= [||]
3602 method getitemcount
= 1 + Array.length m_items
3607 else m_items
.(n-1), 0
3609 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3614 then Buffer.clear
state.errmsgs
;
3615 m_qsearch
<- qsearch;
3622 method hasaction
n =
3626 state.newerrmsgs
<- false;
3627 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
3628 m_items
<- Array.of_list
l
3636 let source = (msgsource :> lvsource
) in
3637 state.uioh <- coe (object
3638 inherit listview ~
source ~trusted
:false as super
3641 then msgsource#reset
;
3644 G.postRedisplay "msgs";
3647 let quickbookmark ?title
() =
3648 match state.layout with
3654 let sec = Unix.gettimeofday
() in
3655 let tm = Unix.localtime
sec in
3656 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
3660 (tm.Unix.tm_year
+ 1900)
3663 | Some
title -> title
3666 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
3671 state.fullscreen
<- None
;
3672 Glut.reshapeWindow
w h;
3675 let viewkeyboard key =
3677 let mode = state.mode in
3678 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
3681 G.postRedisplay "view:enttext"
3683 let c = Char.chr
key in
3685 | '
\027'
| 'q'
-> (* escape *)
3686 begin match state.mstate
with
3688 state.mstate
<- Mnone
;
3689 Glut.setCursor
Glut.CURSOR_INHERIT
;
3690 G.postRedisplay "kill zoom rect";
3695 | '
\008'
-> (* backspace *)
3696 let y = getnav ~
-1 in
3697 gotoy_and_clear_text y
3705 G.postRedisplay "dehighlight";
3708 let ondone isforw
s =
3709 cbput state.hists
.pat
s;
3710 state.searchpattern
<- s;
3713 let s = String.create
1 in
3715 enttext (s, "", Some
(onhist state.hists
.pat
),
3716 textentry, ondone (c ='
/'
))
3718 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3719 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3720 setzoom (conf.zoom +. incr)
3725 try int_of_string
s with exc
->
3726 state.text <- Printf.sprintf
"bad integer `%s': %s"
3727 s (Printexc.to_string exc
);
3733 state.text <- "page bias is now " ^ string_of_int
n;
3736 enttext ("page bias: ", "", None
, intentry, ondone)
3738 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
3739 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3740 setzoom (max
0.01 (conf.zoom -. decr))
3743 let ondone msg
= state.text <- msg
in
3745 "option [acfhilpstvAPRSZTI]: ", "", None
,
3746 optentry state.mode, ondone
3749 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3752 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3753 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
3757 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
3763 try int_of_string
s with exc
->
3764 state.text <- Printf.sprintf
"bad integer `%s': %s"
3765 s (Printexc.to_string exc
);
3771 cbput state.hists
.pag
(string_of_int
n);
3772 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
3775 let pageentry text key =
3776 match Char.unsafe_chr
key with
3777 | 'g'
-> TEdone
text
3778 | _ -> intentry text key
3780 let text = "x" in text.[0] <- c;
3781 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
3784 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
3785 reshape conf.winw
conf.winh
;
3788 conf.hlinks
<- not
conf.hlinks
;
3789 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
3790 G.postRedisplay "toggle highlightlinks";
3793 begin match state.autoscroll
with
3795 conf.autoscrollstep
<- step
;
3796 state.autoscroll
<- None
3798 if conf.autoscrollstep
= 0
3799 then state.autoscroll
<- Some
1
3800 else state.autoscroll
<- Some
conf.autoscrollstep
3804 conf.presentation <- not
conf.presentation;
3805 if conf.presentation
3807 if not
conf.scrollbarinpm
3808 then state.scrollw
<- 0;
3811 state.scrollw
<- conf.scrollbw
;
3813 showtext ' '
("presentation mode " ^
3814 if conf.presentation then "on" else "off");
3815 state.anchor <- getanchor ();
3819 begin match state.fullscreen
with
3821 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
3824 state.fullscreen
<- None
;
3829 gotoy_and_clear_text 0
3832 gotopage1 (state.pagecount
- 1) 0
3835 search state.searchpattern
true
3838 search state.searchpattern
false
3841 begin match state.layout with
3844 gotoy_and_clear_text (getpagey l.pageno)
3848 begin match List.rev
state.layout with
3851 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
3852 gotoy_and_clear_text (getpagey pageno)
3855 | '
\127'
-> (* del *)
3856 begin match state.layout with
3859 let pageno = max
0 (l.pageno-1) in
3860 gotoy_and_clear_text (getpagey pageno)
3864 showtext ' '
(describe_location ());
3867 begin match state.layout with
3870 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
3875 enterbookmarkmode ()
3883 | '
e'
when conf.redirectstderr ->
3888 match state.layout with
3891 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
3895 enttext ("bookmark: ", "", None
, textentry, ondone)
3899 showtext ' '
"Quick bookmark added";
3902 begin match state.layout with
3904 let rect = getpdimrect
l.pagedimno
in
3908 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
3909 truncate
(1.2 *. (rect.(3) -. rect.(0))))
3911 (truncate
(rect.(1) -. rect.(0)),
3912 truncate
(rect.(3) -. rect.(0)))
3914 let w = truncate
((float w)*.conf.zoom)
3915 and h = truncate
((float h)*.conf.zoom) in
3918 state.anchor <- getanchor ();
3919 doreshape (w + state.scrollw
) (h + conf.interpagespace)
3921 G.postRedisplay "z";
3926 | '
\000'
-> (* ctrl-2 *)
3927 let maxw = getmaxw
() in
3929 then setzoom (maxw /. float conf.winw
)
3932 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
3936 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
3938 G.postRedisplay "brightness";
3941 begin match state.mode with
3942 | Birdseye beye
-> upbirdseye beye
3943 | _ -> gotoy (clamp (-conf.scrollstep
))
3947 begin match state.mode with
3948 | Birdseye beye
-> downbirdseye beye
3949 | _ -> gotoy (clamp conf.scrollstep
)
3953 state.anchor <- getanchor ();
3954 opendoc state.path
state.password
3956 | '
v'
when conf.debug
->
3959 match getopaque l.pageno with
3962 let x0, y0
, x1
, y1
= pagebbox opaque
in
3963 let a,b = float x0, float y0
in
3964 let c,d = float x1
, float y0
in
3965 let e,f = float x1
, float y1
in
3966 let h,j
= float x0, float y1
in
3967 let rect = (a,b,c,d,e,f,h,j
) in
3969 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
3971 G.postRedisplay "v";
3974 vlog "huh? %d %c" key (Char.chr
key);
3977 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
3979 | 27 -> (* escape *)
3980 leavebirdseye beye
true
3982 | 12 -> (* ctrl-l *)
3983 let y, h = getpageyh pageno in
3984 let top = (conf.winh
- h) / 2 in
3985 gotoy (max
0 (y - top))
3988 leavebirdseye beye
false
3994 let keyboard ~
key ~
x ~
y =
3997 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
3998 then wcmd "interrupt" []
3999 else state.uioh <- state.uioh#
key key
4002 let birdseyespecial key ((conf, leftx
, _, hooverpageno
, anchor) as beye
) =
4004 | Glut.KEY_UP
-> upbirdseye beye
4005 | Glut.KEY_DOWN
-> downbirdseye beye
4007 | Glut.KEY_PAGE_UP
->
4008 begin match state.layout with
4012 state.mode <- Birdseye
(
4013 conf, leftx
, l.pageno, hooverpageno
, anchor
4015 gotopage1 l.pageno 0;
4018 let layout = layout (state.y-conf.winh
) conf.winh
in
4020 | [] -> gotoy (clamp (-conf.winh
))
4022 state.mode <- Birdseye
(
4023 conf, leftx
, l.pageno, hooverpageno
, anchor
4025 gotopage1 l.pageno 0
4028 | [] -> gotoy (clamp (-conf.winh
))
4031 | Glut.KEY_PAGE_DOWN
->
4032 begin match List.rev
state.layout with
4034 let layout = layout (state.y + conf.winh
) conf.winh
in
4035 begin match layout with
4037 let incr = l.pageh
- l.pagevh in
4042 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4044 G.postRedisplay "birdseye pagedown";
4046 else gotoy (clamp (incr + conf.interpagespace*2));
4050 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
4051 gotopage1 l.pageno 0;
4054 | [] -> gotoy (clamp conf.winh
)
4058 state.mode <- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
4062 let pageno = state.pagecount
- 1 in
4063 state.mode <- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
4064 if not
(pagevisible state.layout pageno)
4067 match List.rev
state.pdims
with
4069 | (_, _, h, _) :: _ -> h
4071 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4072 else G.postRedisplay "birdseye end";
4076 let setautoscrollspeed step goingdown
=
4077 let incr = max
1 ((abs step
) / 2) in
4078 let incr = if goingdown
then incr else -incr in
4079 let astep = step
+ incr in
4080 state.autoscroll
<- Some
astep;
4083 let special ~
key ~
x ~
y =
4086 state.uioh <- state.uioh#
special key
4091 match state.mode with
4092 | Textentry
_ -> scalecolor 0.4
4093 | View
-> scalecolor 1.0
4094 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4095 if l.pageno = hooverpageno
4098 if l.pageno = pageno
4104 begin match getopaque l.pageno with
4106 if tileready l l.pagex l.pagey
4108 let x = l.pagedispx
- l.pagex
4109 and y = l.pagedispy
- l.pagey in
4110 postprocess opaque
conf.hlinks
x y;
4117 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
4118 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
4119 let sh = float conf.winh
/. sh in
4120 let sh = max
sh (float conf.scrollh
) in
4125 else float y /. float maxy
4127 let position = (float conf.winh
-. sh) *. percent in
4130 if position +. sh > float conf.winh
4131 then float conf.winh
-. sh
4138 let winw = conf.winw - state.scrollw
- 1 in
4139 let fwinw = float winw in
4141 let sw = fwinw /. float state.w in
4142 let sw = fwinw *. sw in
4143 max
sw (float conf.scrollh
)
4146 let f = state.w+winw in
4147 let r = float (winw-x) /. float f in
4148 let p = fwinw *. r in
4152 if position +. sw > fwinw
4153 then fwinw -. position
4159 let scrollindicator () =
4160 GlDraw.color (0.64 , 0.64, 0.64);
4162 (float (conf.winw - state.scrollw
), 0.)
4163 (float conf.winw, float conf.winh
)
4166 (0., float (conf.winh
- state.hscrollh))
4167 (float (conf.winw - state.scrollw
- 1), float conf.winh
)
4169 GlDraw.color (0.0, 0.0, 0.0);
4171 let position, sh = scrollph state.y in
4173 (float (conf.winw - state.scrollw
), position)
4174 (float conf.winw, position +. sh)
4176 let position, sw = scrollpw state.x in
4178 (position, float (conf.winh
- state.hscrollh))
4179 (position +. sw, float conf.winh
)
4183 let pagetranslatepoint l x y =
4184 let dy = y - l.pagedispy
in
4185 let y = dy + l.pagey in
4186 let dx = x - l.pagedispx
in
4187 let x = dx + l.pagex in
4192 match state.mstate
with
4193 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4196 | Msel
((x0, y0
), (x1
, y1
)) ->
4197 let rec loop = function
4199 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
4200 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
4202 match getopaque l.pageno with
4204 let dx, dy = pagetranslatepoint l 0 0 in
4209 GlMat.mode `modelview
;
4211 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4212 seltext opaque
(x0, y0
, x1
, y1
);
4223 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4224 GlDraw.polygon_mode `both `fill
;
4225 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4227 (fun (pageno, c, (x0, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
4229 if l.pageno = pageno
4231 let dx = float (l.pagedispx
- l.pagex) in
4232 let dy = float (l.pagedispy
- l.pagey) in
4233 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4234 GlDraw.begins `quads
;
4236 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4237 GlDraw.vertex2
(x1
+.dx, y1
+.dy);
4238 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4239 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4250 GlClear.color (scalecolor2 conf.bgcolor
);
4251 GlClear.clear
[`
color];
4252 List.iter
drawpage state.layout;
4257 begin match state.mstate
with
4258 | Mzoomrect
((x0, y0
), (x1
, y1
)) ->
4260 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4261 GlDraw.polygon_mode `both `fill
;
4262 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4263 GlDraw.rect (float x0, float y0
)
4264 (float x1
, float y1
);
4269 Glut.swapBuffers
();
4273 let rec f = function
4275 begin match getopaque l.pageno with
4277 let x0 = l.pagedispx
in
4278 let x1 = x0 + l.pagevw in
4279 let y0 = l.pagedispy
in
4280 let y1 = y0 + l.pagevh in
4281 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4283 let px, py = pagetranslatepoint l x y in
4284 match whatsunder opaque
px py with
4296 let zoomrect x y x1 y1 =
4299 and y0 = min
y y1 in
4300 gotoy (state.y + y0);
4301 state.anchor <- getanchor ();
4302 let zoom = (float conf.winw *. conf.zoom) /. float (x1 - x0) in
4304 if state.w < conf.winw - state.scrollw
4305 then (conf.winw - state.scrollw
- state.w) / 2
4308 state.x <- (state.x + margin) - x0;
4310 Glut.setCursor
Glut.CURSOR_INHERIT
;
4311 state.mstate
<- Mnone
;
4315 let winw = conf.winw - state.scrollw
- 1 in
4316 let s = float x /. float winw in
4317 let destx = truncate
(float (state.w + winw) *. s) in
4318 state.x <- winw - destx;
4319 gotoy_and_clear_text state.y;
4320 state.mstate
<- Mscrollx
;
4324 let s = float y /. float conf.winh
in
4325 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4326 gotoy_and_clear_text desty;
4327 state.mstate
<- Mscrolly
;
4330 let viewmouse button bstate
x y =
4332 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4333 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4335 match state.mstate
with
4336 | Mzoom
(oldn
, i
) ->
4344 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4346 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4348 let zoom = conf.zoom -. incr in
4350 state.mstate
<- Mzoom
(n, 0);
4352 state.mstate
<- Mzoom
(n, i
+1);
4354 else state.mstate
<- Mzoom
(n, 0)
4356 | _ -> state.mstate
<- Mzoom
(n, 0)
4359 match state.autoscroll
with
4360 | Some step
-> setautoscrollspeed step
(n=4)
4364 then -conf.scrollstep
4365 else conf.scrollstep
4367 let incr = incr * 2 in
4368 let y = clamp incr in
4369 gotoy_and_clear_text y
4372 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4373 if bstate
= Glut.DOWN
4375 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4376 state.mstate
<- Mpan
(x, y)
4379 state.mstate
<- Mnone
4381 | Glut.RIGHT_BUTTON
->
4382 if bstate
= Glut.DOWN
4384 Glut.setCursor
Glut.CURSOR_CYCLE
;
4386 state.mstate
<- Mzoomrect
(p, p)
4389 match state.mstate
with
4390 | Mzoomrect
((x0, y0), _) -> zoomrect x0 y0 x y
4392 Glut.setCursor
Glut.CURSOR_INHERIT
;
4393 state.mstate
<- Mnone
4396 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4397 if bstate
= Glut.DOWN
4399 let position, sh = scrollph state.y in
4400 if y > truncate
position && y < truncate
(position +. sh)
4401 then state.mstate
<- Mscrolly
4404 state.mstate
<- Mnone
4406 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4407 if bstate
= Glut.DOWN
4409 let position, sw = scrollpw state.x in
4410 if x > truncate
position && x < truncate
(position +. sw)
4411 then state.mstate
<- Mscrollx
4414 state.mstate
<- Mnone
4416 | Glut.LEFT_BUTTON
->
4417 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4418 begin match dest with
4419 | Ulinkgoto
(pageno, top) ->
4423 gotopage1 pageno top;
4429 | Unone
when bstate
= Glut.DOWN
->
4430 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4431 state.mstate
<- Mpan
(x, y);
4433 | Unone
| Utext
_ ->
4434 if bstate
= Glut.DOWN
4436 if conf.angle
mod 360 = 0
4438 state.mstate
<- Msel
((x, y), (x, y));
4439 G.postRedisplay "mouse select";
4443 match state.mstate
with
4446 | Mzoom
_ | Mscrollx
| Mscrolly
->
4447 state.mstate
<- Mnone
4449 | Mzoomrect
((x0, y0), _) ->
4453 Glut.setCursor
Glut.CURSOR_INHERIT
;
4454 state.mstate
<- Mnone
4456 | Msel
((_, y0), (_, y1)) ->
4458 if (y0 >= l.pagedispy
&& y0 <= (l.pagedispy
+ l.pagevh))
4459 || ((y1 >= l.pagedispy
&& y1 <= (l.pagedispy
+ l.pagevh)))
4461 match getopaque l.pageno with
4466 List.iter
f state.layout;
4467 copysel
""; (* ugly *)
4468 Glut.setCursor
Glut.CURSOR_INHERIT
;
4469 state.mstate
<- Mnone
;
4476 let birdseyemouse button bstate
x y
4477 (conf, leftx
, _, hooverpageno
, anchor) =
4479 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4480 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4481 let rec loop = function
4484 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4485 && x > margin && x < margin + l.pagew
4487 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4492 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4496 let mouse bstate button
x y =
4497 state.uioh <- state.uioh#button button bstate
x y;
4500 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4503 state.uioh <- state.uioh#
motion x y
4507 state.uioh <- state.uioh#
pmotion x y;
4514 begin match state.mode with
4515 | Textentry
textentry -> textentrykeyboard key textentry
4516 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4517 | View
-> viewkeyboard key
4521 method special key =
4522 begin match state.mode with
4523 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
4527 birdseyespecial key vals
4529 | View
when key = Glut.KEY_F1
->
4533 begin match state.autoscroll
with
4534 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
4535 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
4540 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
4542 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4544 if Glut.getModifiers
() land Glut.active_shift
!= 0
4545 then (setzoom state.prevzoom
; state.y)
4546 else clamp (-conf.winh
/2)
4547 else clamp (-conf.scrollstep
)
4549 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4551 if Glut.getModifiers
() land Glut.active_shift
!= 0
4552 then (setzoom state.prevzoom
; state.y)
4553 else clamp (conf.winh
/2)
4554 else clamp (conf.scrollstep
)
4555 | Glut.KEY_PAGE_UP
->
4556 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4558 match state.layout with
4560 | l :: _ -> state.y - l.pagey
4563 | Glut.KEY_PAGE_DOWN
->
4564 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4566 match List.rev
state.layout with
4568 | l :: _ -> getpagey l.pageno
4576 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
4578 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
4579 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
4580 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
4582 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
4584 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4585 then (conf.winw / 2)
4588 state.x <- state.x - dx;
4590 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
4592 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4593 then (conf.winw / 2)
4596 state.x <- state.x + dx;
4601 gotoy_and_clear_text y
4604 | Textentry
te -> textentryspecial key te
4608 method button button bstate
x y =
4609 begin match state.mode with
4610 | View
-> viewmouse button bstate
x y
4611 | Birdseye beye
-> birdseyemouse button bstate
x y beye
4617 begin match state.mode with
4619 | View
| Birdseye
_ ->
4620 match state.mstate
with
4621 | Mzoom
_ | Mnone
-> ()
4626 state.mstate
<- Mpan
(x, y);
4627 if conf.zoom > 1.0 then state.x <- state.x + dx;
4629 gotoy_and_clear_text y
4632 state.mstate
<- Msel
(a, (x, y));
4633 G.postRedisplay "motion select";
4636 let y = min
conf.winh
(max
0 y) in
4640 let x = min
conf.winw (max
0 x) in
4643 | Mzoomrect
(p0
, _) ->
4644 state.mstate
<- Mzoomrect
(p0
, (x, y));
4645 G.postRedisplay "motion zoomrect";
4649 method pmotion x y =
4650 begin match state.mode with
4651 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
4652 let margin = (conf.winw - (state.w + state.scrollw
)) / 2 in
4653 let rec loop = function
4655 if hooverpageno
!= -1
4657 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
4658 G.postRedisplay "pmotion birdseye no hoover";
4661 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
4662 && x > margin && x < margin + l.pagew
4664 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
4665 G.postRedisplay "pmotion birdseye hoover";
4674 match state.mstate
with
4676 begin match getunder x y with
4677 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
4679 if conf.underinfo
then showtext 'u'
("ri: " ^
uri);
4680 Glut.setCursor
Glut.CURSOR_INFO
4681 | Ulinkgoto
(page
, _) ->
4683 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
4684 Glut.setCursor
Glut.CURSOR_INFO
4686 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
4687 Glut.setCursor
Glut.CURSOR_TEXT
4690 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
4695 method infochanged
_ = ()
4702 let fontpath = ref "";;
4703 let wmclasshack = ref false;;
4706 let l = String.length
s in
4707 let b = Buffer.create
l in
4715 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
4716 | _ -> Sys.getenv
"HOME"
4719 ("Can not determine home directory location: " ^
4720 Printexc.to_string exn
);
4724 let config_of c attrs
=
4728 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
4729 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
4730 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
4731 | "preload" -> { c with preload = bool_of_string
v }
4732 | "page-bias" -> { c with pagebias
= int_of_string
v }
4733 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
4734 | "auto-scroll-step" ->
4735 { c with autoscrollstep
= max
0 (int_of_string
v) }
4736 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
4737 | "crop-hack" -> { c with crophack
= bool_of_string
v }
4740 match String.lowercase
v with
4741 | "true" -> Some infinity
4743 | f -> Some
(float_of_string
f)
4745 { c with maxwait
= mw}
4746 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
4747 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
4748 | "vertical-margin" ->
4749 { c with interpagespace = max
0 (int_of_string
v) }
4751 let zoom = float_of_string
v /. 100. in
4752 let zoom = max
zoom 0.0 in
4753 { c with zoom = zoom }
4754 | "presentation" -> { c with presentation = bool_of_string
v }
4755 | "rotation-angle" -> { c with angle
= int_of_string
v }
4756 | "width" -> { c with winw = max
20 (int_of_string
v) }
4757 | "height" -> { c with winh
= max
20 (int_of_string
v) }
4758 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
4759 | "proportional-display" -> { c with proportional
= bool_of_string
v }
4760 | "pixmap-cache-size" ->
4761 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
4762 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
4763 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
4764 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
4765 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
4766 | "background-color" -> { c with bgcolor
= color_of_string v }
4767 | "scrollbar-in-presentation" ->
4768 { c with scrollbarinpm
= bool_of_string
v }
4769 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
4770 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
4771 | "mupdf-memlimit" ->
4772 { c with mumemlimit
= max
1024 (int_of_string_with_suffix v) }
4773 | "checkers" -> { c with checkers
= bool_of_string
v }
4774 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
4775 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
4776 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
4777 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
4778 | "uri-launcher" -> { c with urilauncher
= unent v }
4779 | "color-space" -> { c with colorspace
= colorspace_of_string v }
4780 | "invert-colors" -> { c with invert
= bool_of_string
v }
4781 | "brightness" -> { c with colorscale
= float_of_string
v }
4782 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
4785 prerr_endline
("Error processing attribute (`" ^
4786 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
4789 let rec fold c = function
4792 let c = apply c k
v in
4798 let fromstring f pos
n v d =
4801 dolog "Error processing attribute (%S=%S) at %d\n%s"
4802 n v pos
(Printexc.to_string exn
)
4807 let bookmark_of attrs
=
4808 let rec fold title page rely
= function
4809 | ("title", v) :: rest
-> fold v page rely rest
4810 | ("page", v) :: rest
-> fold title v rely rest
4811 | ("rely", v) :: rest
-> fold title page
v rest
4812 | _ :: rest
-> fold title page rely rest
4813 | [] -> title, page
, rely
4815 fold "invalid" "0" "0" attrs
4819 let rec fold path page rely pan
= function
4820 | ("path", v) :: rest
-> fold v page rely pan rest
4821 | ("page", v) :: rest
-> fold path
v rely pan rest
4822 | ("rely", v) :: rest
-> fold path page
v pan rest
4823 | ("pan", v) :: rest
-> fold path page rely
v rest
4824 | _ :: rest
-> fold path page rely pan rest
4825 | [] -> path
, page
, rely
, pan
4827 fold "" "0" "0" "0" attrs
4830 let setconf dst
src =
4831 dst
.scrollbw
<- src.scrollbw
;
4832 dst
.scrollh
<- src.scrollh
;
4833 dst
.icase
<- src.icase
;
4834 dst
.preload <- src.preload;
4835 dst
.pagebias
<- src.pagebias
;
4836 dst
.verbose
<- src.verbose
;
4837 dst
.scrollstep
<- src.scrollstep
;
4838 dst
.maxhfit
<- src.maxhfit
;
4839 dst
.crophack
<- src.crophack
;
4840 dst
.autoscrollstep
<- src.autoscrollstep
;
4841 dst
.maxwait
<- src.maxwait
;
4842 dst
.hlinks
<- src.hlinks
;
4843 dst
.underinfo
<- src.underinfo
;
4844 dst
.interpagespace <- src.interpagespace;
4845 dst
.zoom <- src.zoom;
4846 dst
.presentation <- src.presentation;
4847 dst
.angle
<- src.angle
;
4848 dst
.winw <- src.winw;
4849 dst
.winh
<- src.winh
;
4850 dst
.savebmarks
<- src.savebmarks
;
4851 dst
.memlimit
<- src.memlimit
;
4852 dst
.proportional
<- src.proportional
;
4853 dst
.texcount
<- src.texcount
;
4854 dst
.sliceheight
<- src.sliceheight
;
4855 dst
.thumbw
<- src.thumbw
;
4856 dst
.jumpback
<- src.jumpback
;
4857 dst
.bgcolor
<- src.bgcolor
;
4858 dst
.scrollbarinpm
<- src.scrollbarinpm
;
4859 dst
.tilew
<- src.tilew
;
4860 dst
.tileh
<- src.tileh
;
4861 dst
.mumemlimit
<- src.mumemlimit
;
4862 dst
.checkers
<- src.checkers
;
4863 dst
.aalevel
<- src.aalevel
;
4864 dst
.trimmargins
<- src.trimmargins
;
4865 dst
.trimfuzz
<- src.trimfuzz
;
4866 dst
.urilauncher
<- src.urilauncher
;
4867 dst
.colorspace
<- src.colorspace
;
4868 dst
.invert
<- src.invert
;
4869 dst
.colorscale
<- src.colorscale
;
4870 dst
.redirectstderr <- src.redirectstderr;
4874 let h = Hashtbl.create
10 in
4875 let dc = { defconf with angle
= defconf.angle
} in
4876 let rec toplevel v t spos
_ =
4878 | Vdata
| Vcdata
| Vend
-> v
4879 | Vopen
("llppconfig", _, closed
) ->
4882 else { v with f = llppconfig
}
4884 error
"unexpected subelement at top level" s spos
4885 | Vclose
_ -> error
"unexpected close at top level" s spos
4887 and llppconfig
v t spos
_ =
4889 | Vdata
| Vcdata
-> v
4890 | Vend
-> error
"unexpected end of input in llppconfig" s spos
4891 | Vopen
("defaults", attrs
, closed
) ->
4892 let c = config_of dc attrs
in
4896 else { v with f = skip
"defaults" (fun () -> v) }
4898 | Vopen
("ui-font", attrs
, closed
) ->
4899 let rec getsize size
= function
4901 | ("size", v) :: rest
->
4903 fromstring int_of_string spos
"size" v fstate.fontsize
in
4905 | l -> getsize size l
4907 fstate.fontsize
<- getsize fstate.fontsize attrs
;
4910 else { v with f = uifont
(Buffer.create
10) }
4912 | Vopen
("doc", attrs
, closed
) ->
4913 let pathent, spage
, srely
, span
= doc_of attrs
in
4914 let path = unent pathent
4915 and pageno = fromstring int_of_string spos
"page" spage
0
4916 and rely
= fromstring float_of_string spos
"rely" srely
0.0
4917 and pan
= fromstring int_of_string spos
"pan" span
0 in
4918 let c = config_of dc attrs
in
4919 let anchor = (pageno, rely
) in
4921 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
4922 else { v with f = doc
path pan
anchor c [] }
4925 error
"unexpected subelement in llppconfig" s spos
4927 | Vclose
"llppconfig" -> { v with f = toplevel }
4928 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
4930 and uifont
b v t spos epos
=
4933 Buffer.add_substring
b s spos
(epos
- spos
);
4935 | Vopen
(_, _, _) ->
4936 error
"unexpected subelement in ui-font" s spos
4937 | Vclose
"ui-font" ->
4938 if String.length
!fontpath = 0
4939 then fontpath := Buffer.contents
b;
4940 { v with f = llppconfig
}
4941 | Vclose
_ -> error
"unexpected close in ui-font" s spos
4942 | Vend
-> error
"unexpected end of input in ui-font" s spos
4944 and doc
path pan
anchor c bookmarks
v t spos
_ =
4946 | Vdata
| Vcdata
-> v
4947 | Vend
-> error
"unexpected end of input in doc" s spos
4948 | Vopen
("bookmarks", _, closed
) ->
4951 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
4953 | Vopen
(_, _, _) ->
4954 error
"unexpected subelement in doc" s spos
4957 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
4958 { v with f = llppconfig
}
4960 | Vclose
_ -> error
"unexpected close in doc" s spos
4962 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
4964 | Vdata
| Vcdata
-> v
4965 | Vend
-> error
"unexpected end of input in bookmarks" s spos
4966 | Vopen
("item", attrs
, closed
) ->
4967 let titleent, spage
, srely
= bookmark_of attrs
in
4968 let page = fromstring int_of_string spos
"page" spage
0
4969 and rely
= fromstring float_of_string spos
"rely" srely
0.0 in
4970 let bookmarks = (unent titleent, 0, (page, rely
)) :: bookmarks in
4972 then { v with f = pbookmarks
path pan
anchor c bookmarks }
4975 { v with f = skip
"item" f }
4978 error
"unexpected subelement in bookmarks" s spos
4980 | Vclose
"bookmarks" ->
4981 { v with f = doc
path pan
anchor c bookmarks }
4983 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
4985 and skip tag
f v t spos
_ =
4987 | Vdata
| Vcdata
-> v
4989 error
("unexpected end of input in skipped " ^ tag
) s spos
4990 | Vopen
(tag'
, _, closed
) ->
4994 let f'
() = { v with f = skip tag
f } in
4995 { v with f = skip tag'
f'
}
4999 else error
("unexpected close in skipped " ^ tag
) s spos
5002 parse
{ f = toplevel; accu = () } s;
5008 let len = in_channel_length ic
in
5009 let s = String.create
len in
5010 really_input ic
s 0 len;
5013 | Parse_error
(msg
, s, pos
) ->
5014 let subs = subs s pos
in
5015 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5016 failwith
("parse error: " ^
s)
5019 failwith
("config load error: " ^
Printexc.to_string exn
)
5025 let dir = Filename.concat
home ".config" in
5026 if Sys.is_directory
dir then dir else home
5029 Filename.concat
dir "llpp.conf"
5032 let confpath = ref defconfpath;;
5035 if Sys.file_exists
!confpath
5038 (try Some
(open_in_bin
!confpath)
5041 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5042 Printexc.to_string exn
);
5051 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5052 Printexc.to_string exn
);
5058 f (Hashtbl.create
0, defconf)
5063 let pc, pb
, px, pa
=
5065 Hashtbl.find h (Filename.basename
state.path)
5066 with Not_found
-> dc, [], 0, (0, 0.0)
5070 state.bookmarks <- pb
;
5072 state.scrollw
<- conf.scrollbw
;
5074 then state.anchor <- pa
;
5075 cbput state.hists
.nav pa
;
5080 let add_attrs bb always
dc c =
5083 then Printf.bprintf bb
"\n %s='%b'" s a
5086 then Printf.bprintf bb
"\n %s='%d'" s a
5089 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5092 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5095 then Printf.bprintf bb
"\n %s='%f'" s a
5099 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5103 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5107 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5111 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5121 else string_of_float
f
5123 Printf.bprintf bb
"\n %s='%s'" s v
5127 then dc.winw, dc.winh
5129 match state.fullscreen
with
5131 | None
-> c.winw, c.winh
5133 let zoom, presentation, interpagespace, maxwait
=
5135 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5137 match state.mode with
5138 | Birdseye
(bc
, _, _, _, _) ->
5139 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5140 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5142 oi
"width" w dc.winw;
5143 oi
"height" h dc.winh
;
5144 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5145 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5146 ob "case-insensitive-search" c.icase
dc.icase
;
5147 ob "preload" c.preload dc.preload;
5148 oi
"page-bias" c.pagebias
dc.pagebias
;
5149 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5150 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5151 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5152 ob "crop-hack" c.crophack
dc.crophack
;
5153 oW
"throttle" maxwait
dc.maxwait
;
5154 ob "highlight-links" c.hlinks
dc.hlinks
;
5155 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5156 oi
"vertical-margin" interpagespace dc.interpagespace;
5157 oz
"zoom" zoom dc.zoom;
5158 ob "presentation" presentation dc.presentation;
5159 oi
"rotation-angle" c.angle
dc.angle
;
5160 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5161 ob "proportional-display" c.proportional
dc.proportional
;
5162 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5163 oi
"tex-count" c.texcount
dc.texcount
;
5164 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5165 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5166 ob "persistent-location" c.jumpback
dc.jumpback
;
5167 oc
"background-color" c.bgcolor
dc.bgcolor
;
5168 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5169 oi
"tile-width" c.tilew
dc.tilew
;
5170 oi
"tile-height" c.tileh
dc.tileh
;
5171 oI
"mupdf-memlimit" c.mumemlimit
dc.mumemlimit
;
5172 ob "checkers" c.checkers
dc.checkers
;
5173 oi
"aalevel" c.aalevel
dc.aalevel
;
5174 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5175 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5176 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5177 oC
"color-space" c.colorspace
dc.colorspace
;
5178 ob "invert-colors" c.invert
dc.invert
;
5179 oF
"brightness" c.colorscale
dc.colorscale
;
5180 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5182 then ob "wmclass-hack" !wmclasshack false;
5186 let uifontsize = fstate.fontsize
in
5187 let bb = Buffer.create
32768 in
5189 let dc = if conf.bedefault
then conf else dc in
5190 Buffer.add_string
bb "<llppconfig>\n";
5192 if String.length
!fontpath > 0
5194 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5200 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5203 Buffer.add_string
bb "<defaults ";
5204 add_attrs bb true dc dc;
5205 Buffer.add_string
bb "/>\n";
5207 let adddoc path pan
anchor c bookmarks =
5208 if bookmarks == [] && c = dc && anchor = emptyanchor
5211 Printf.bprintf
bb "<doc path='%s'"
5212 (enent
path 0 (String.length
path));
5214 if anchor <> emptyanchor
5216 let n, y = anchor in
5217 Printf.bprintf
bb " page='%d'" n;
5220 Printf.bprintf
bb " rely='%f'" y
5225 then Printf.bprintf
bb " pan='%d'" pan
;
5227 add_attrs bb false dc c;
5229 begin match bookmarks with
5230 | [] -> Buffer.add_string
bb "/>\n"
5232 Buffer.add_string
bb ">\n<bookmarks>\n";
5233 List.iter
(fun (title, _level
, (page, rely
)) ->
5235 "<item title='%s' page='%d'"
5236 (enent
title 0 (String.length
title))
5241 Printf.bprintf
bb " rely='%f'" rely
5243 Buffer.add_string
bb "/>\n";
5245 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5251 match state.mode with
5252 | Birdseye
(_, pan, _, _, _) -> pan
5255 let basename = Filename.basename state.path in
5256 adddoc basename pan (getanchor ())
5259 match state.autoscroll
with
5261 | None
-> conf.autoscrollstep
}
5262 (if conf.savebmarks
then state.bookmarks else []);
5264 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5266 then adddoc path x y c bookmarks
5268 Buffer.add_string
bb "</llppconfig>";
5271 if Buffer.length
bb > 0
5274 let tmp = !confpath ^
".tmp" in
5275 let oc = open_out_bin
tmp in
5276 Buffer.output_buffer
oc bb;
5278 Unix.rename
tmp !confpath;
5281 ("error while saving configuration: " ^
Printexc.to_string exn
)
5288 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5289 "<password> Set password");
5291 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5292 "<path> Set path to the user interface font");
5294 ("-c", Arg.String
(fun s -> Config.confpath := s),
5295 "<path> Set path to the configuration file");
5297 ("-v", Arg.Unit
(fun () ->
5299 "%s\nconfiguration path: %s\n"
5303 exit
0), " Print version and exit");
5306 (fun s -> state.path <- s)
5307 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5309 if String.length
state.path = 0
5310 then (prerr_endline
"file name missing"; exit
1);
5314 let _ = Glut.init
Sys.argv
in
5315 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5316 let () = Glut.initWindowSize
conf.winw conf.winh
in
5317 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5319 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5320 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5321 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5326 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5328 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5329 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5330 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5331 Unix.bind
sock addr;
5333 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5334 Unix.connect
csock addr;
5335 let ssock, _ = Unix.accept
sock in
5338 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5339 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5346 let () = Glut.displayFunc
display in
5347 let () = Glut.reshapeFunc
reshape in
5348 let () = Glut.keyboardFunc
keyboard in
5349 let () = Glut.specialFunc
special in
5350 let () = Glut.idleFunc
(Some
idle) in
5351 let () = Glut.mouseFunc
mouse in
5352 let () = Glut.motionFunc
motion in
5353 let () = Glut.passiveMotionFunc
pmotion in
5355 setcheckers conf.checkers
;
5357 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5358 conf.texcount
, conf.sliceheight
, conf.mumemlimit
, conf.colorspace
,
5359 !Config.wmclasshack, !Config.fontpath
5361 state.csock <- csock;
5362 state.ssock <- ssock;
5363 state.text <- "Opening " ^
state.path;
5364 setaalevel
conf.aalevel
;
5365 writeopen state.path state.password
;
5367 setfontsize fstate.fontsize
;
5375 | Glut.BadEnum
"key in special_of_int" ->
5376 showtext '
!'
" LablGlut bug: special key not recognized";
5383 | exn
when conf.redirectstderr ->
5385 Printf.sprintf
"exception %s\n%s"
5386 (Printexc.to_string exn
)
5387 (Printexc.get_backtrace
())
5390 Unix.single_write
state.stderr
s 0 (String.length
s);