4 | Ulinkgoto
of (int * int)
6 and facename
= string;;
8 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
10 type params
= angle
* proportional
* texcount
* sliceheight
19 and proportional
= bool
20 and interpagespace
= int
27 external init
: Unix.file_descr
-> params
-> unit = "ml_init";;
28 external draw
: (int * int * int * int * bool) -> string -> unit = "ml_draw";;
29 external seltext
: string -> (int * int * int * int) -> int -> unit =
31 external copysel
: string -> unit = "ml_copysel";;
32 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
33 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
34 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
38 | Msel
of (mpos
* mpos
)
41 | Mzoom
of (int * int)
45 type textentry
= char
* string * onhist
* onkey
* ondone
46 and onkey
= string -> int -> te
47 and ondone
= string -> unit
48 and histcancel
= unit -> unit
49 and onhist
= ((histcmd
-> string) * histcancel
) option
50 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
55 | TEswitch
of textentry
67 { store
= Array.create n v
74 let cbcap b
= Array.length b
.store
;;
79 b
.wc
<- (b
.wc
+ 1) mod cap;
81 b
.len
<- min
(b
.len
+ 1) cap;
84 let cbempty b
= b
.len
= 0;;
86 let cbgetg b circular dir
=
90 let rc = b
.rc + dir
in
102 else max
0 (min
rc (b
.len
-1))
108 let cbget b
= cbgetg b
false;;
109 let cbgetc b
= cbgetg b
true;;
112 let rc = b
.wc
- b
.len
in
113 let rc = if rc < 0 then cbcap b
+ rc else rc in
117 let cbdecr b
= b
.len
<- b
.len
- 1;;
132 { mutable scrollw
: int
133 ; mutable scrollh
: int
134 ; mutable icase
: bool
135 ; mutable preload
: bool
136 ; mutable pagebias
: int
137 ; mutable verbose
: bool
138 ; mutable scrollstep
: int
139 ; mutable maxhfit
: bool
140 ; mutable crophack
: bool
141 ; mutable autoscrollstep
: int
142 ; mutable showall
: bool
143 ; mutable hlinks
: bool
144 ; mutable underinfo
: bool
145 ; mutable interpagespace
: interpagespace
146 ; mutable zoom
: float
147 ; mutable presentation
: bool
148 ; mutable angle
: angle
151 ; mutable savebmarks
: bool
152 ; mutable proportional
: proportional
153 ; mutable memlimit
: int
154 ; mutable texcount
: texcount
155 ; mutable sliceheight
: sliceheight
156 ; mutable thumbw
: width
157 ; mutable jumpback
: bool
161 type outline
= string * int * int * float;;
163 | Oarray
of outline array
164 | Olist
of outline list
165 | Onarrow
of string * outline array
* outline array
168 type rect
= float * float * float * float * float * float * float * float;;
170 type pagemapkey
= pageno
* width
* angle
* proportional
* gen
;;
172 type anchor
= pageno
* top
;;
174 let emptyanchor = (0, 0.0);;
175 let initialanchor = (-1, nan
);;
178 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
179 | Outline
of (bool * int * int * outline array
* string * int)
180 | Textentry
of (textentry
* mode
)
184 let isbirdseye = function Birdseye _
-> true | _
-> false;;
185 let istextentry = function Textentry _
-> true | _
-> false;;
188 { mutable csock
: Unix.file_descr
189 ; mutable ssock
: Unix.file_descr
193 ; mutable anchor
: anchor
195 ; mutable layout
: layout list
196 ; pagemap
: (pagemapkey
, (opaque
* pixmapsize
)) Hashtbl.t
197 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
198 ; mutable pagecount
: int
199 ; pagecache
: string circbuf
200 ; mutable rendering
: bool
201 ; mutable mstate
: mstate
202 ; mutable searchpattern
: string
203 ; mutable rects
: (pageno
* recttype
* rect
) list
204 ; mutable rects1
: (pageno
* recttype
* rect
) list
205 ; mutable text
: string
206 ; mutable fullscreen
: (width
* height
) option
207 ; mutable mode
: mode
208 ; mutable outlines
: outlines
209 ; mutable bookmarks
: outline list
210 ; mutable path
: string
211 ; mutable password
: string
212 ; mutable invalidated
: int
213 ; mutable colorscale
: float
214 ; mutable memused
: int
216 ; mutable throttle
: layout list
option
217 ; mutable ascrollstep
: int
218 ; mutable help
: string list
219 ; mutable docinfo
: (int * string) list
223 { pat
: string circbuf
224 ; pag
: string circbuf
225 ; nav
: anchor circbuf
239 ; autoscrollstep
= 24
245 ; presentation
= false
250 ; proportional
= true
251 ; memlimit
= 32*1024*1024
259 let conf = { defconf with angle
= defconf.angle
};;
266 ; anchor
= initialanchor
270 ; pagemap
= Hashtbl.create
10
271 ; pagecache
= cbnew 100 ""
282 ; outlines
= Olist
[]
288 { nav
= cbnew 100 (0, 0.0)
305 Printf.kprintf prerr_endline fmt
307 Printf.kprintf ignore fmt
311 let len = String.length s
in
313 let b = Buffer.create
n in
314 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
315 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
316 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
317 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
318 Buffer.add_string
b s
;
319 let s'
= Buffer.contents
b in
320 let n'
= Unix.write fd
s'
0 n in
321 if n'
!= n then failwith
"write failed";
326 let n = Unix.read fd
s 0 4 in
327 if n != 4 then failwith
"incomplete read(len)";
329 lor (Char.code
s.[0] lsl 24)
330 lor (Char.code
s.[1] lsl 16)
331 lor (Char.code
s.[2] lsl 8)
332 lor (Char.code
s.[3] lsl 0)
334 let s = String.create
len in
335 let n = Unix.read fd
s 0 len in
336 if n != len then failwith
"incomplete read(data)";
341 let b = Buffer.create
10 in
342 Buffer.add_string
b s;
343 let rec combine = function
346 Buffer.add_char
b ' '
;
349 | `
b b -> if b then "1" else "0"
351 | `i i
-> string_of_int i
352 | `f f
-> string_of_float f
353 | `I f
-> string_of_int
(truncate f
)
355 Buffer.add_string
b s;
362 let cmd = Buffer.contents
(makecmd s l
) in
363 writecmd state.csock
cmd;
369 let d = conf.winh
- h
in
376 let rec f pn ph pi fh l
=
378 | (n, _
, h
, _
) :: rest
->
379 let ips = calcips h
in
384 if isbirdseye state.mode
&& pn
= 0
389 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
394 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
398 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
401 let fh = f 0 0 0 0 state.pdims
in
405 let getpageyh pageno
=
406 let rec f pn ph pi y l
=
408 | (n, _
, h
, _
) :: rest
->
409 let ips = calcips h
in
412 let h = if n = pageno
then h else ph
in
413 if conf.presentation
&& n = pageno
415 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
417 y
+ (pageno
- pn
) * (ph
+ pi
), h
419 let y = y + (if conf.presentation
then pi
else 0) in
420 let y = y + (n - pn
) * (ph
+ pi
) in
424 y + (pageno
- pn
) * (ph
+ pi
), ph
426 f 0 0 0 0 state.pdims
429 let getpagey pageno
= fst
(getpageyh pageno
);;
432 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~cacheleft ~accu
=
433 let ((w
, h, ips, x
) as curr
), rest
, pdimno
, yinc
=
435 | (pageno'
, w
, h, x
) :: rest
when pageno'
= pageno
->
436 let ips = calcips h in
438 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
442 (w
, h, ips, x
), rest
, pdimno
+ 1, yinc
444 prev
, pdims
, pdimno
, 0
446 let dy = dy + yinc in
447 let py = py + yinc in
448 if pageno
= state.pagecount
|| cacheleft
= 0 || dy >= sh
453 if py + h <= vy - yinc
455 let py = py + h + ips in
456 let dy = max
0 (py - y) in
466 let pagey = vy - py in
467 let pagevh = h - pagey in
468 let pagevh = min
(sh
- dy) pagevh in
469 let off = if yinc > 0 then py - vy else 0 in
470 let py = py + h + ips in
476 ; pagedispy
= dy + off
477 ; pagey = pagey + off
478 ; pagevh = pagevh - off
482 let accu = e :: accu in
489 ~cacheleft
:(cacheleft
-1)
492 if state.invalidated
= 0
502 ~cacheleft
:(cbcap state.pagecache
)
512 let y = state.y + incr
in
514 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
518 let getopaque pageno
=
519 try Some
(Hashtbl.find
state.pagemap
520 (pageno
, state.w
, conf.angle
, conf.proportional
, state.gen
))
521 with Not_found
-> None
524 let cache pageno opaque
=
525 Hashtbl.replace
state.pagemap
526 (pageno
, state.w
, conf.angle
, conf.proportional
, state.gen
) opaque
529 let validopaque opaque
= String.length opaque
> 0;;
532 match getopaque l
.pageno
with
533 | None
when not
state.rendering
->
534 state.rendering
<- true;
535 cache l
.pageno
("", -1);
536 wcmd "render" [`i
(l
.pageno
+ 1)
543 let loadlayout layout =
544 let rec f all
= function
546 begin match getopaque l
.pageno
with
547 | None
-> render l
; f false ls
548 | Some
(opaque
, _
) -> f (all
&& validopaque opaque
) ls
552 f (layout <> []) layout;
555 let findpageforopaque opaque
=
557 (fun k
(v
, s) a
-> if v
= opaque
then Some
(k
, s) else a
)
561 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
567 let memleft = conf.memlimit
- state.memused
in
570 let opaque = cbpeek state.pagecache
in
571 match findpageforopaque opaque with
572 | Some
((n, _
, _
, _
, _
), size
) ->
573 memleft + size
>= 0 && not
(pagevisible state.layout n)
580 let presentation = conf.presentation in
581 let interpagespace = conf.interpagespace in
582 let maxy = state.maxy in
583 conf.presentation <- false;
584 conf.interpagespace <- 0;
585 state.maxy <- calcheight ();
587 match state.layout with
589 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
591 let y = if y < conf.winh
then 0 else y - conf.winh
in
592 let pages = layout y (conf.winh
*3) in
593 List.iter
render pages;
594 conf.presentation <- presentation;
595 conf.interpagespace <- interpagespace;
601 let y = min
state.maxy y in
602 let pages = layout y conf.winh
in
603 let ready = loadlayout pages in
609 state.layout <- pages;
610 state.throttle
<- None
;
611 Glut.postRedisplay
();
614 state.throttle
<- Some
pages;
619 state.layout <- pages;
620 state.throttle
<- None
;
621 Glut.postRedisplay
();
623 begin match state.mode
with
624 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
625 if not
(pagevisible pages pageno
)
627 match state.layout with
630 state.mode
<- Birdseye
(conf, leftx
, l
.pageno
, hooverpageno
, anchor
)
637 let gotoy_and_clear_text y =
639 if not
conf.verbose
then state.text
<- "";
643 match state.layout with
645 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
648 let getanchory (n, top
) =
649 let y, h = getpageyh n in
650 y + (truncate
(top
*. float h));
653 let gotoanchor anchor
=
654 gotoy (getanchory anchor
);
658 cbput state.hists
.nav
(getanchor ());
662 let anchor = cbgetc state.hists
.nav ~
-1 in
667 let y, h = getpageyh n in
668 gotoy_and_clear_text (y + (truncate
(top
*. float h)));
671 let gotopage1 n top
=
672 let y = getpagey n in
673 gotoy_and_clear_text (y + top
);
681 state.invalidated
<- state.invalidated
+ 1;
685 let c = c *. state.colorscale
in
690 state.maxy <- calcheight ();
691 match state.mode
with
692 | Birdseye
(_
, _
, pageno
, _
, _
) ->
693 let y, h = getpageyh pageno
in
694 let top = (conf.winh
- h) / 2 in
695 gotoy (max
0 (y - top))
696 | _
-> gotoanchor state.anchor
700 GlMat.mode `projection
;
701 GlMat.load_identity
();
702 GlMat.rotate ~x
:1.0 ~angle
:180.0 ();
703 GlMat.translate ~x
:~
-.1.0 ~
y:~
-.1.0 ();
704 GlMat.scale3
(2.0 /. float state.w
, 2.0 /. float conf.winh
, 1.0);
707 GlMat.translate ~x
:(float state.x
) ();
712 GlMat.mode `projection
;
713 GlMat.load_identity
();
714 GlMat.rotate ~x
:1.0 ~angle
:180.0 ();
715 GlMat.translate ~x
:~
-.1.0 ~
y:~
-.1.0 ();
716 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
720 if state.invalidated
= 0 && state.anchor == initialanchor
721 then state.anchor <- getanchor ();
724 let w = truncate
(float w *. conf.zoom
) - conf.scrollw
in
728 GlMat.mode `modelview
;
729 GlMat.load_identity
();
730 GlClear.color
(scalecolor 1.0);
731 GlClear.clear
[`color
];
734 wcmd "geometry" [`i
w; `i
h];
738 GlDraw.color
(0.0, 0.0, 0.0);
740 (0.0, float (conf.winh
- 18))
741 (float (conf.winw
- conf.scrollw
- 1), float conf.winh
)
743 let font = Glut.BITMAP_8_BY_13
in
744 GlDraw.color
(1.0, 1.0, 1.0);
745 GlPix.raster_pos ~x
:0.0 ~
y:(float (conf.winh
- 5)) ();
746 Glut.bitmapCharacter ~
font ~
c:(Char.code
c);
747 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c)) s;
751 let len = String.length
state.text
in
752 match state.mode
with
753 | Textentry
((c, text
, _
, _
, _
), _
) ->
757 text ^
" [" ^
state.text ^
"]"
764 if len > 0 then showtext ' '
state.text
768 state.text
<- Printf.sprintf
"%c%s" c s;
769 Glut.postRedisplay
();
778 state.rects
<- state.rects1
;
779 Glut.postRedisplay
()
782 let n = Scanf.sscanf
cmd "C %u" (fun n -> n) in
783 state.pagecount
<- n;
784 state.invalidated
<- state.invalidated
- 1;
785 if state.invalidated
= 0
789 let s = Scanf.sscanf
cmd "t %n"
790 (fun n -> String.sub
cmd n (String.length
cmd - n))
792 Glut.setWindowTitle
s
795 let s = Scanf.sscanf
cmd "T %n"
796 (fun n -> String.sub
cmd n (String.length
cmd - n))
798 if istextentry state.mode
805 Glut.postRedisplay
();
811 let s = Scanf.sscanf
cmd "V %n"
812 (fun n -> String.sub
cmd n (String.length
cmd - n))
818 let pageno, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
819 Scanf.sscanf
cmd "F %u %d %f %f %f %f %f %f %f %f"
820 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
821 (p
, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
823 let y = (getpagey pageno) + truncate y0
in
826 state.rects1
<- [pageno, c, (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
)]
829 let pageno, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
830 Scanf.sscanf
cmd "R %u %d %f %f %f %f %f %f %f %f"
831 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
832 (p
, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
835 (pageno, c, (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) :: state.rects1
838 let n, w, h, r
, l
, s, p
=
839 Scanf.sscanf
cmd "r %u %u %u %u %d %u %s"
840 (fun n w h r l
s p
->
841 (n-1, w, h, r
, l
!= 0, s, p
))
844 Hashtbl.replace
state.pagemap
(n, w, r
, l
, state.gen
) (p
, s);
845 state.memused
<- state.memused
+ s;
848 match state.throttle
with
849 | None
-> state.layout
850 | Some
layout -> layout
854 if (state.memused
<= conf.memlimit
) || cbempty state.pagecache
857 let evictedopaque = cbpeek state.pagecache
in
858 match findpageforopaque evictedopaque with
859 | None
-> failwith
"bug in gc"
860 | Some
((evictedn
, _
, _
, _
, gen
) as k
, evictedsize
) ->
861 if state.gen
!= gen
|| not
(pagevisible layout evictedn
)
863 wcmd "free" [`
s evictedopaque];
864 state.memused
<- state.memused
- evictedsize
;
865 Hashtbl.remove
state.pagemap k
;
866 cbdecr state.pagecache
;
873 cbput state.pagecache p
;
874 state.rendering
<- false;
876 begin match state.throttle
with
878 if pagevisible state.layout n
881 let allvisible = loadlayout state.layout in
882 if allvisible then preload ();
889 let y = getpagey l
.pageno + l
.pagey in
894 let (n, w, h, x
) as pdim
=
895 Scanf.sscanf
cmd "l %u %u %u %u" (fun n w h x
-> n, w, h, x
)
897 state.pdims
<- pdim
:: state.pdims
900 let (l
, n, t
, h, pos
) =
901 Scanf.sscanf
cmd "o %u %u %d %u %n" (fun l
n t
h pos
-> l
, n, t
, h, pos
)
903 let s = String.sub
cmd pos
(String.length
cmd - pos
) in
905 let l = String.length
s in
906 let b = Buffer.create
(String.length
s) in
913 | '
\xa0'
when pc2 -> Buffer.add_char
b ' '
; false
916 let c = if Char.code
c land 0x80 = 0 then c else '?'
in
925 let outline = (s, l, n, float t
/. float h) in
927 match state.outlines with
928 | Olist
outlines -> Olist
(outline :: outlines)
929 | Oarray _
-> Olist
[outline]
930 | Onarrow _
-> Olist
[outline]
932 state.outlines <- outlines
936 let s = Scanf.sscanf
cmd "i %n"
937 (fun n -> String.sub
cmd n (String.length
cmd - n))
939 let len = String.length
s in
940 let rec fold accu pos
=
942 try String.index_from
s pos '
\n'
with Not_found
-> len
947 let line = String.sub
s pos
(eolpos - pos
) in
948 fold ((1, line)::accu) (eolpos+1)
950 state.docinfo
<- fold state.docinfo
0
953 dolog "unknown cmd `%S'" cmd
956 let now = Unix.gettimeofday
;;
960 let r, _
, _
= Unix.select
[state.csock
] [] [] delay
in
963 if state.ascrollstep
> 0
965 let y = state.y + state.ascrollstep
in
966 let y = if y >= state.maxy then 0 else y in
972 let cmd = readcmd state.csock
in
981 let action = function
982 | HCprev
-> cbget cb ~
-1
983 | HCnext
-> cbget cb
1
984 | HCfirst
-> cbget cb ~
-(cb
.rc)
985 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
986 and cancel
() = cb
.rc <- rc
990 let search pattern forward
=
991 if String.length pattern
> 0
994 match state.layout with
997 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
1000 let b = makecmd "search"
1001 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
1003 Buffer.add_char
b '
,'
;
1004 Buffer.add_string
b pattern
;
1005 Buffer.add_char
b '
\000'
;
1008 writecmd state.csock
cmd;
1011 let intentry text key
=
1012 let c = Char.unsafe_chr key
in
1015 let s = "x" in s.[0] <- c;
1016 let text = text ^
s in
1020 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1025 let b = Buffer.create
(String.length
s + 1) in
1026 Buffer.add_string
b s;
1027 Buffer.add_char
b c;
1031 let textentry text key
=
1032 let c = Char.unsafe_chr key
in
1034 | _
when key
>= 32 && key
< 127 ->
1035 let text = addchar text c in
1039 dolog "unhandled key %d char `%c'" key
(Char.unsafe_chr key
);
1043 let reinit angle proportional
=
1044 conf.angle
<- angle
;
1045 conf.proportional
<- proportional
;
1047 wcmd "reinit" [`i angle
; `
b proportional
];
1051 let zoom = max
0.01 (min
2.2 zoom) in
1052 if zoom <> conf.zoom
1057 reshape conf.winw
conf.winh
;
1058 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
1062 let enterbirdseye () =
1063 let zoom = float conf.thumbw
/. float conf.winw
in
1064 let birdseyepageno =
1065 let rec fold candidate
= function
1067 | l :: _
when l.pagey = 0 -> l.pageno
1068 | l :: rest
-> fold l.pageno rest
1072 state.mode
<- Birdseye
(
1073 { conf with zoom = conf.zoom }, state.x
, birdseyepageno, -1, getanchor ()
1076 conf.presentation <- false;
1077 conf.interpagespace <- 10;
1078 conf.hlinks
<- false;
1080 state.mstate
<- Mnone
;
1081 conf.showall
<- false;
1082 Glut.setCursor
Glut.CURSOR_INHERIT
;
1085 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1090 reshape conf.winw
conf.winh
;
1093 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
1095 conf.zoom <- c.zoom;
1096 conf.presentation <- c.presentation;
1097 conf.interpagespace <- c.interpagespace;
1098 conf.showall
<- c.showall
;
1099 conf.hlinks
<- c.hlinks
;
1103 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1106 reshape conf.winw
conf.winh
;
1107 state.anchor <- if goback
then anchor else (pageno, 0.0);
1110 let togglebirdseye () =
1111 match state.mode
with
1112 | Birdseye vals
-> leavebirdseye vals
true
1113 | View
| Outline _
-> enterbirdseye ()
1117 let optentry text key
=
1118 let btos b = if b then "on" else "off" in
1119 let c = Char.unsafe_chr key
in
1123 try conf.scrollstep
<- int_of_string
s with exc
->
1124 state.text <- Printf.sprintf
"bad integer `%s': %s"
1125 s (Printexc.to_string exc
)
1127 TEswitch
('#'
, "", None
, intentry, ondone)
1132 conf.autoscrollstep
<- int_of_string
s;
1133 if state.ascrollstep
> 0
1134 then state.ascrollstep
<- conf.autoscrollstep
;
1136 state.text <- Printf.sprintf
"bad integer `%s': %s"
1137 s (Printexc.to_string exc
)
1139 TEswitch
('
*'
, "", None
, intentry, ondone)
1144 let zoom = float (int_of_string
s) /. 100.0 in
1147 state.text <- Printf.sprintf
"bad integer `%s': %s"
1148 s (Printexc.to_string exc
)
1150 TEswitch
('
@'
, "", None
, intentry, ondone)
1155 conf.thumbw
<- max
2 (min
1920 (int_of_string
s));
1157 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
1158 begin match state.mode
with
1159 | Textentry
(_
, Birdseye beye
) ->
1160 leavebirdseye beye
false;
1165 state.text <- Printf.sprintf
"bad integer `%s': %s"
1166 s (Printexc.to_string exc
)
1168 TEswitch
('$'
, "", None
, intentry, ondone)
1173 Some
(int_of_string
s)
1175 state.text <- Printf.sprintf
"bad integer `%s': %s"
1176 s (Printexc.to_string exc
);
1179 | Some angle
-> reinit angle
conf.proportional
1182 TEswitch
('^'
, "", None
, intentry, ondone)
1185 conf.icase
<- not
conf.icase
;
1186 TEdone
("case insensitive search " ^
(btos conf.icase
))
1189 conf.preload <- not
conf.preload;
1191 TEdone
("preload " ^
(btos conf.preload))
1194 conf.verbose
<- not
conf.verbose
;
1195 TEdone
("verbose " ^
(btos conf.verbose
))
1198 conf.maxhfit
<- not
conf.maxhfit
;
1199 state.maxy <- state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
1200 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
1203 conf.crophack
<- not
conf.crophack
;
1204 TEdone
("crophack " ^
btos conf.crophack
)
1207 conf.showall
<- not
conf.showall
;
1208 TEdone
("showall " ^
btos conf.showall
)
1211 conf.underinfo
<- not
conf.underinfo
;
1212 TEdone
("underinfo " ^
btos conf.underinfo
)
1215 conf.savebmarks
<- not
conf.savebmarks
;
1216 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
1222 match state.layout with
1227 conf.interpagespace <- int_of_string
s;
1228 state.maxy <- calcheight ();
1229 let y = getpagey pageno in
1232 state.text <- Printf.sprintf
"bad integer `%s': %s"
1233 s (Printexc.to_string exc
)
1235 TEswitch
('
%'
, "", None
, intentry, ondone)
1238 reinit conf.angle
(not
conf.proportional
);
1239 TEdone
("proprortional display " ^
btos conf.proportional
)
1242 state.text <- Printf.sprintf
"bad option %d `%c'" key
c;
1246 let maxoutlinerows () = (conf.winh
- 31) / 16;;
1248 let enterselector allowdel
outlines errmsg msg
=
1249 if Array.length
outlines = 0
1251 showtext ' ' errmsg
;
1255 Glut.setCursor
Glut.CURSOR_INHERIT
;
1257 match state.layout with
1259 | {pageno=pageno} :: rest
-> pageno
1263 if n = Array.length
outlines
1266 let (_
, _
, outlinepageno
, _
) = outlines.(n) in
1267 if outlinepageno
>= pageno then n else loop (n+1)
1271 state.mode
<- Outline
1272 (allowdel
, active, max
0 (active - maxoutlinerows () / 2), outlines, "", 0);
1273 Glut.postRedisplay
();
1277 let enteroutlinemode () =
1279 match state.outlines with
1282 let a = Array.of_list
(List.rev
l) in
1283 state.outlines <- Oarray
a;
1285 | Onarrow
(pat
, a, b) ->
1286 a, "Outline was narrowed to `" ^ pat ^
"' (Ctrl-u to restore)"
1288 enterselector false outlines "Document has no outline" msg
;
1291 let enterbookmarkmode () =
1292 let bookmarks = Array.of_list
state.bookmarks in
1293 enterselector true bookmarks "Document has no bookmarks (yet)" "";
1296 let enterinfomode () =
1297 let btos = function true -> "on" | _
-> "off" in
1298 let pageno, top = getanchor () in
1300 let autoscrollstep =
1301 if state.ascrollstep
> 0
1302 then state.ascrollstep
1303 else conf.autoscrollstep
1305 (0, "Current parameters")
1306 :: (1, "presentation mode " ^
btos conf.presentation)
1307 :: (1, "case insensitive search " ^
btos conf.icase
)
1308 :: (1, "preload " ^
btos conf.preload)
1309 :: (1, "page bias " ^ string_of_int
conf.pagebias
)
1310 :: (1, "verbose " ^
btos conf.verbose
)
1311 :: (1, "scroll step " ^ string_of_int
conf.scrollstep
)
1312 :: (1, "max fit " ^
btos conf.maxhfit
)
1313 :: (1, "crop hack " ^
btos conf.crophack
)
1314 :: (1, "autoscroll step " ^ string_of_int
autoscrollstep)
1315 :: (1, "throttle " ^
btos conf.showall
)
1316 :: (1, "highlight links " ^
btos conf.hlinks
)
1317 :: (1, "under info " ^
btos conf.underinfo
)
1318 :: (1, "veritcal margin " ^ string_of_int
conf.interpagespace)
1319 :: (1, "zoom " ^
Printf.sprintf
"%-5.1f" (conf.zoom*.100.))
1320 :: (1, "rotation " ^ string_of_int
conf.angle
)
1321 :: (1, "persistent bookmarks " ^
btos conf.savebmarks
)
1322 :: (1, "proportional display " ^
btos conf.proportional
)
1323 :: (1, "pixmap cache size " ^ string_of_int
conf.memlimit
)
1324 :: (1, "pixmap cache used " ^ string_of_int
state.memused
)
1325 :: (1, "thumbnail width " ^ string_of_int
conf.thumbw
)
1326 :: (1, "persistent location " ^
btos conf.jumpback
)
1327 :: (1, Printf.sprintf
"window dimensions %dx%d " conf.winw
conf.winh
)
1328 :: (0, "Document information")
1329 :: (1, string_of_int
state.pagecount ^
" pages")
1333 let o = Array.create
(List.length
info) ("", 0, pageno, top) in
1334 let rec iteri i
= function
1337 o.(i
) <- (s, l, pageno, top);
1343 enterselector false o "Info not available" "";
1346 let enterhelpmode () =
1347 let pageno, top = getanchor () in
1349 let help = ("Keys for llpp version " ^
Help.version
) :: state.help in
1350 let o = Array.create
(List.length
help) ("", 0, pageno, top) in
1351 let rec iteri i
= function
1354 o.(i
) <- (s, (if i
= 0 then 0 else 1), pageno, top);
1360 enterselector false o "Help not available" "";
1363 let quickbookmark ?title
() =
1364 match state.layout with
1370 let sec = Unix.gettimeofday
() in
1371 let tm = Unix.localtime
sec in
1372 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
1376 (tm.Unix.tm_year
+ 1900)
1379 | Some
title -> title
1382 (title, 0, l.pageno, float l.pagey /. float l.pageh
) :: state.bookmarks
1386 state.fullscreen
<- None
;
1387 Glut.reshapeWindow
w h;
1390 let writeopen path password
=
1391 writecmd state.csock
("open " ^ path ^
"\000" ^
state.password ^
"\000");
1392 writecmd state.csock
"info";
1395 let opendoc path password
=
1398 state.password
<- password
;
1399 state.gen
<- state.gen
+ 1;
1401 writeopen path password
;
1402 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1403 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1406 let viewkeyboard ~key ~x ~
y =
1408 state.mode
<- Textentry
(te
, state.mode
);
1411 Glut.postRedisplay
()
1413 let c = Char.chr key
in
1419 let y = getnav () in
1420 gotoy_and_clear_text y
1428 Glut.postRedisplay
()
1431 let ondone isforw
s =
1432 cbput state.hists
.pat
s;
1433 state.searchpattern
<- s;
1436 enttext (c, "", Some
(onhist state.hists
.pat
),
1437 textentry, ondone (c ='
/'
))
1439 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
1440 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
1441 setzoom (min
2.2 (conf.zoom +. incr))
1446 try int_of_string
s with exc
->
1447 state.text <- Printf.sprintf
"bad integer `%s': %s"
1448 s (Printexc.to_string exc
);
1454 state.text <- "page bias is now " ^ string_of_int
n;
1457 enttext ('
+'
, "", None
, intentry, ondone)
1459 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
1460 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
1461 setzoom (max
0.01 (conf.zoom -. decr))
1467 enttext ('
-'
, "", None
, optentry, ondone)
1469 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1472 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1473 let zoom = zoomforh
conf.winw
conf.winh
conf.scrollw
in
1477 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1483 try int_of_string
s with exc
->
1484 state.text <- Printf.sprintf
"bad integer `%s': %s"
1485 s (Printexc.to_string exc
);
1491 cbput state.hists
.pag
(string_of_int
n);
1492 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
1495 let pageentry text key
=
1496 match Char.unsafe_chr key
with
1497 | 'g'
-> TEdone
text
1498 | _
-> intentry text key
1500 let text = "x" in text.[0] <- c;
1501 enttext ('
:'
, text, Some
(onhist state.hists
.pag
), pageentry, ondone)
1504 conf.scrollw
<- if conf.scrollw
> 0 then 0 else defconf.scrollw
;
1505 reshape conf.winw
conf.winh
;
1508 conf.hlinks
<- not
conf.hlinks
;
1509 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
1510 Glut.postRedisplay
()
1513 if state.ascrollstep
= 0
1514 then state.ascrollstep
<- conf.autoscrollstep
1516 conf.autoscrollstep <- state.ascrollstep
;
1517 state.ascrollstep
<- 0;
1521 conf.presentation <- not
conf.presentation;
1522 showtext ' '
("presentation mode " ^
1523 if conf.presentation then "on" else "off");
1524 state.anchor <- getanchor ();
1528 begin match state.fullscreen
with
1530 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
1533 state.fullscreen
<- None
;
1538 gotoy_and_clear_text 0
1541 search state.searchpattern
true
1544 search state.searchpattern
false
1547 begin match state.layout with
1550 gotoy_and_clear_text (getpagey l.pageno)
1554 begin match List.rev
state.layout with
1557 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
1558 gotoy_and_clear_text (getpagey pageno)
1562 begin match state.layout with
1565 let pageno = max
0 (l.pageno-1) in
1566 gotoy_and_clear_text (getpagey pageno)
1571 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
1573 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
1575 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
1579 else (100. *. (float state.y /. float maxy)) in
1582 Printf.sprintf
"Page %d of %d %.2f%%"
1583 (fn+1) state.pagecount
percent
1586 "Pages %d-%d of %d %.2f%%"
1587 (fn+1) (ln
+1) state.pagecount
percent
1592 begin match state.layout with
1595 doreshape (l.pagew
+ conf.scrollw
) l.pageh
;
1596 Glut.postRedisplay
();
1600 enterbookmarkmode ()
1610 match state.layout with
1613 (s, 0, l.pageno, float l.pagey /. float l.pageh
)
1617 enttext ('~'
, "", None
, textentry, ondone)
1621 showtext ' '
"Quick bookmark added";
1624 begin match state.layout with
1626 let rect = getpdimrect
l.pagedimno
in
1630 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
1631 truncate
(1.2 *. (rect.(3) -. rect.(0))))
1633 (truncate
(rect.(1) -. rect.(0)),
1634 truncate
(rect.(3) -. rect.(0)))
1638 doreshape (w + conf.scrollw
) (h + conf.interpagespace)
1640 Glut.postRedisplay
();
1646 reinit (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
1651 (min
(state.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 1.0);
1652 Glut.postRedisplay
()
1654 | 'k'
-> gotoy (clamp (-conf.scrollstep
))
1655 | 'j'
-> gotoy (clamp conf.scrollstep
)
1657 | '
r'
-> opendoc state.path
state.password
1660 vlog "huh? %d %c" key
(Char.chr key
);
1663 let textentrykeyboard ~key ~x ~
y ((c, text, opthist
, onkey
, ondone), mode
) =
1665 state.mode
<- Textentry
(te
, mode
);
1668 Glut.postRedisplay
()
1670 match Char.unsafe_chr key
with
1672 let len = String.length
text in
1676 Glut.postRedisplay
();
1679 let s = String.sub
text 0 (len - 1) in
1680 enttext (c, s, opthist
, onkey
, ondone)
1686 Glut.postRedisplay
()
1689 begin match opthist
with
1691 | Some
(_
, onhistcancel
) -> onhistcancel
()
1694 Glut.postRedisplay
()
1697 begin match onkey
text key
with
1701 Glut.postRedisplay
()
1704 enttext (c, text, opthist
, onkey
, ondone);
1708 Glut.postRedisplay
()
1711 state.mode
<- Textentry
(te
, mode
);
1712 Glut.postRedisplay
()
1716 let birdseyekeyboard ~key ~x ~
y ((_
, _
, pageno, _
, anchor) as beye
) =
1719 leavebirdseye beye
true
1722 let y, h = getpageyh pageno in
1723 let top = (conf.winh
- h) / 2 in
1724 gotoy (max
0 (y - top))
1727 leavebirdseye beye
false
1730 viewkeyboard ~key ~x ~
y
1733 let outlinekeyboard ~key ~x ~
y
1734 (allowdel
, active, first
, outlines, qsearch
, pan
) =
1735 let narrow outlines pattern
=
1736 let reopt = try Some
(Str.regexp_case_fold pattern
) with _
-> None
in
1740 let rec fold accu n =
1744 let (s, _
, _
, _
) as o = outlines.(n) in
1746 if (try ignore
(Str.search_forward re
s 0); true
1747 with Not_found
-> false)
1753 let matched = fold [] (Array.length
outlines - 1) in
1754 if matched = [] then None
else Some
(Array.of_list
matched)
1756 let search active pattern
incr =
1759 if n = Array.length
outlines || n = -1
1762 let (s, _
, _
, _
) = outlines.(n) in
1764 (try ignore
(Str.search_forward re
s 0); true
1765 with Not_found
-> false)
1767 else loop (n + incr)
1772 let re = Str.regexp_case_fold pattern
in
1778 let firstof active = max
0 (active - maxoutlinerows () / 2) in
1781 if String.length qsearch
= 0
1785 Glut.postRedisplay
();
1789 state.mode
<- Outline
(allowdel
, active, first
, outlines, "", pan
);
1790 Glut.postRedisplay
();
1794 let incr = if key
= 18 then -1 else 1 in
1796 match search (active + incr) qsearch
incr with
1798 state.text <- qsearch ^
" [not found]";
1801 state.text <- qsearch
;
1802 active, firstof active
1804 state.mode
<- Outline
(allowdel
, active, first
, outlines, qsearch
, pan
);
1805 Glut.postRedisplay
();
1808 let len = String.length qsearch
in
1815 state.mode
<- Outline
(allowdel
, active, first
, outlines, "", pan
);
1818 let qsearch = String.sub
qsearch 0 (len - 1) in
1820 match search active qsearch ~
-1 with
1822 state.text <- qsearch ^
" [not found]";
1825 state.text <- qsearch;
1826 active, firstof active
1828 state.mode
<- Outline
(allowdel
, active, first
, outlines, qsearch, pan
);
1830 Glut.postRedisplay
()
1833 if active < Array.length
outlines
1835 let (_
, _
, n, t
) = outlines.(active) in
1840 if allowdel
then state.bookmarks <- Array.to_list
outlines;
1842 Glut.postRedisplay
();
1844 | _
when key
>= 32 && key
< 127 ->
1845 let pattern = addchar qsearch (Char.chr key
) in
1847 match search active pattern 1 with
1849 state.text <- pattern ^
" [not found]";
1852 state.text <- pattern;
1853 active, firstof active
1855 state.mode
<- Outline
(allowdel
, active, first
, outlines, pattern, pan
);
1856 Glut.postRedisplay
()
1858 | 14 when not allowdel
-> (* ctrl-n *)
1859 if String.length
qsearch > 0
1861 let optoutlines = narrow outlines qsearch in
1862 begin match optoutlines with
1863 | None
-> state.text <- "can't narrow"
1865 state.mode
<- Outline
(allowdel
, 0, 0, outlines, qsearch, pan
);
1866 match state.outlines with
1869 state.outlines <- Onarrow
(qsearch, outlines, a)
1870 | Onarrow
(pat
, a, b) ->
1871 state.outlines <- Onarrow
(qsearch, outlines, b)
1874 Glut.postRedisplay
()
1876 | 21 when not allowdel
-> (* ctrl-u *)
1878 match state.outlines with
1881 let a = Array.of_list
(List.rev
l) in
1882 state.outlines <- Oarray
a;
1884 | Onarrow
(pat
, a, b) ->
1885 state.outlines <- Oarray
b;
1889 state.mode
<- Outline
(allowdel
, 0, 0, outline, qsearch, pan
);
1890 Glut.postRedisplay
()
1893 state.mode
<- Outline
1894 (allowdel
, active, firstof active, outlines, qsearch, pan
);
1895 Glut.postRedisplay
()
1897 | 127 when allowdel
->
1898 let len = Array.length
outlines - 1 in
1902 state.bookmarks <- [];
1905 let bookmarks = Array.init
len
1907 let i = if i >= active then i + 1 else i in
1920 Glut.postRedisplay
()
1922 | _
-> dolog "unknown key %d" key
1925 let keyboard ~key ~x ~
y =
1930 match state.mode
with
1931 | Outline
outline -> outlinekeyboard ~key ~x ~
y outline
1932 | Textentry
textentry -> textentrykeyboard ~key ~x ~
y textentry
1933 | Birdseye birdseye
-> birdseyekeyboard ~key ~x ~
y birdseye
1934 | View
-> viewkeyboard ~key ~x ~
y
1937 let birdseyespecial key x
y (conf, leftx
, pageno, hooverpageno
, anchor) =
1940 let pageno = max
0 (pageno - 1) in
1941 let rec loop = function
1942 | [] -> gotopage1 pageno 0
1943 | l :: _
when l.pageno = pageno ->
1944 if l.pagedispy
>= 0 && l.pagey = 0
1945 then Glut.postRedisplay
()
1946 else gotopage1 pageno 0
1947 | _
:: rest
-> loop rest
1950 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
1953 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
1954 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
1955 let rec loop = function
1957 let y, h = getpageyh pageno in
1958 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
1960 | l :: rest
when l.pageno = pageno ->
1961 if l.pagevh != l.pageh
1962 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
1963 else Glut.postRedisplay
()
1964 | l :: rest
-> loop rest
1968 | Glut.KEY_PAGE_UP
->
1969 begin match state.layout with
1973 state.mode
<- Birdseye
(
1974 conf, leftx
, l.pageno, hooverpageno
, anchor
1976 gotopage1 l.pageno 0;
1979 let layout = layout (state.y-conf.winh
) conf.winh
in
1981 | [] -> gotoy (clamp (-conf.winh
))
1983 state.mode
<- Birdseye
(
1984 conf, leftx
, l.pageno, hooverpageno
, anchor
1986 gotopage1 l.pageno 0
1989 | [] -> gotoy (clamp (-conf.winh
))
1992 | Glut.KEY_PAGE_DOWN
->
1993 begin match List.rev
state.layout with
1995 let layout = layout (state.y + conf.winh
) conf.winh
in
1996 begin match layout with
1998 let incr = l.pageh
- l.pagevh in
2003 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
2005 Glut.postRedisplay
();
2007 else gotoy (clamp (incr + conf.interpagespace*2));
2011 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
2012 gotopage1 l.pageno 0;
2015 | [] -> gotoy (clamp conf.winh
)
2019 state.mode
<- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
2023 let pageno = state.pagecount
- 1 in
2024 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2025 if not
(pagevisible state.layout pageno)
2028 match List.rev
state.pdims
with
2030 | (_
, _
, h, _
) :: _
-> h
2032 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
2033 else Glut.postRedisplay
();
2037 let setautoscrollspeed goingdown
=
2038 let incr = max
1 (state.ascrollstep
/ 2) in
2039 let astep = max
1 (state.ascrollstep
+ (if goingdown
then incr else -incr)) in
2040 state.ascrollstep
<- astep;
2043 let special ~key ~x ~
y =
2044 match state.mode
with
2045 | View
| (Birdseye _
) when key
= Glut.KEY_F9
->
2049 birdseyespecial key x
y vals
2051 | View
when key
= Glut.KEY_F1
->
2055 if state.ascrollstep
> 0 && (key
= Glut.KEY_DOWN
|| key
= Glut.KEY_UP
)
2056 then setautoscrollspeed (key
= Glut.KEY_DOWN
)
2060 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
2061 | Glut.KEY_UP
-> clamp (-conf.scrollstep
)
2062 | Glut.KEY_DOWN
-> clamp conf.scrollstep
2063 | Glut.KEY_PAGE_UP
->
2064 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2066 match state.layout with
2068 | l :: _
-> state.y - l.pagey
2071 | Glut.KEY_PAGE_DOWN
->
2072 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2074 match List.rev
state.layout with
2076 | l :: _
-> getpagey l.pageno
2079 | Glut.KEY_HOME
-> addnav (); 0
2082 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
2084 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
2085 state.x
<- state.x
- 10;
2087 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
2088 state.x
<- state.x
+ 10;
2093 gotoy_and_clear_text y
2096 ((c, s, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2099 | Glut.KEY_UP
-> action HCprev
2100 | Glut.KEY_DOWN
-> action HCnext
2101 | Glut.KEY_HOME
-> action HCfirst
2102 | Glut.KEY_END
-> action HClast
2105 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2106 Glut.postRedisplay
()
2110 | Outline
(allowdel
, active, first
, outlines, qsearch, pan
) ->
2111 let maxrows = maxoutlinerows () in
2112 let calcfirst first
active =
2115 let rows = active - first
in
2116 if rows > maxrows then active - maxrows else first
2120 let active = active + incr in
2121 let active = max
0 (min
active (Array.length
outlines - 1)) in
2122 let first = calcfirst first active in
2123 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch, pan
);
2124 Glut.postRedisplay
()
2126 let updownlevel incr =
2127 let len = Array.length
outlines in
2128 let (_
, curlevel
, _
, _
) = outlines.(active) in
2130 if i = len then i-1 else if i = -1 then 0 else
2131 let (_
, l, _
, _
) = outlines.(i) in
2132 if l != curlevel
then i else flow (i+incr)
2134 let active = flow active in
2135 let first = calcfirst first active in
2136 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch, pan
);
2137 Glut.postRedisplay
()
2140 | Glut.KEY_UP
-> navigate ~
-1
2141 | Glut.KEY_DOWN
-> navigate 1
2142 | Glut.KEY_PAGE_UP
-> navigate ~
-maxrows
2143 | Glut.KEY_PAGE_DOWN
-> navigate maxrows
2146 if Glut.active_ctrl
!= 0
2148 state.mode
<- Outline
(
2149 allowdel
, active, first, outlines, qsearch, min
0 (pan
+ 1)
2151 Glut.postRedisplay
();
2159 if Glut.active_ctrl
!= 0
2161 state.mode
<- Outline
(
2162 allowdel
, active, first, outlines, qsearch, pan
- 1
2164 Glut.postRedisplay
();
2168 then updownlevel ~
-1
2172 state.mode
<- Outline
(allowdel
, 0, 0, outlines, qsearch, pan
);
2173 Glut.postRedisplay
()
2176 let active = Array.length
outlines - 1 in
2177 let first = max
0 (active - maxrows) in
2178 state.mode
<- Outline
(
2179 allowdel
, active, first, outlines, qsearch, pan
2181 Glut.postRedisplay
()
2186 let drawplaceholder l =
2187 let margin = state.x
+ (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2189 (float l.pagex
, float l.pagedispy
)
2190 (float (l.pagew
+ l.pagex
), float (l.pagedispy
+ l.pagevh))
2192 let x = float (if margin < 0 then -margin else l.pagex
)
2193 and y = float (l.pagedispy
+ 13) in
2194 let font = Glut.BITMAP_8_BY_13
in
2195 GlDraw.color
(0.0, 0.0, 0.0);
2196 GlPix.raster_pos ~
x ~
y ();
2197 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c))
2198 ("Loading " ^ string_of_int
(l.pageno + 1));
2201 let now () = Unix.gettimeofday
();;
2205 match state.mode
with
2206 | Textentry _
-> scalecolor 0.4
2207 | View
| Outline _
-> scalecolor 1.0
2208 | Birdseye
(_
, _
, pageno, hooverpageno
, _
) ->
2209 if l.pageno = hooverpageno
2212 if l.pageno = pageno
2218 begin match getopaque l.pageno with
2219 | Some
(opaque, _
) when validopaque opaque ->
2221 draw
(l.pagedispy
, l.pagew
, l.pagevh, l.pagey, conf.hlinks
)
2225 vlog "draw %d %f sec" l.pageno d;
2233 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
2234 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2235 let sh = float conf.winh
/. sh in
2236 let sh = max
sh (float conf.scrollh
) in
2239 if state.y = state.maxy
2241 else float y /. float maxy
2243 let position = (float conf.winh
-. sh) *. percent in
2246 if position +. sh > float conf.winh
2247 then float conf.winh
-. sh
2253 let scrollindicator () =
2254 GlDraw.color (0.64 , 0.64, 0.64);
2256 (float (conf.winw
- conf.scrollw
), 0.)
2257 (float conf.winw
, float conf.winh
)
2259 GlDraw.color (0.0, 0.0, 0.0);
2261 let position, sh = scrollph state.y in
2263 (float (conf.winw
- conf.scrollw
), position)
2264 (float conf.winw
, position +. sh)
2268 let showsel margin =
2269 match state.mstate
with
2270 | Mnone
| Mscroll _
| Mpan _
| Mzoom _
->
2273 | Msel
((x0
, y0
), (x1
, y1
)) ->
2274 let rec loop = function
2276 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
2277 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
2279 match getopaque l.pageno with
2280 | Some
(opaque, _
) when validopaque opaque ->
2281 let oy = -l.pagey + l.pagedispy
in
2283 (x0
- margin - state.x, y0
,
2284 x1
- margin - state.x, y1
) oy;
2294 let panx = float state.x in
2296 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
2297 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2299 (fun (pageno, c, (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
2301 if l.pageno = pageno
2303 let d = float (l.pagedispy
- l.pagey) in
2304 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
2305 GlDraw.begins `quads
;
2307 GlDraw.vertex2
(x0
+.panx, y0
+.d);
2308 GlDraw.vertex2
(x1
+.panx, y1
+.d);
2309 GlDraw.vertex2
(x2
+.panx, y2
+.d);
2310 GlDraw.vertex2
(x3
+.panx, y3
+.d);
2320 let showoutline () =
2321 match state.mode
with
2322 | Outline
(allowdel
, active, first, outlines, qsearch, pan
) ->
2324 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2325 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2326 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2329 GlDraw.color (1., 1., 1.);
2330 let font = Glut.BITMAP_9_BY_15
in
2331 let draw_string x y s =
2332 GlPix.raster_pos ~
x ~
y ();
2333 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c)) s
2336 if row
= Array.length
outlines || (row
- first) * 16 > conf.winh
2339 let (s, l, _
, _
) = outlines.(row
) in
2340 let y = (row
- first) * 16 in
2345 GlDraw.polygon_mode `both `
line;
2346 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2347 GlDraw.color (1., 1., 1.) ~alpha
:0.9;
2348 GlDraw.rect (0., float (y + 1))
2349 (float (conf.winw
- 1), float (y + 18));
2350 GlDraw.polygon_mode `both `fill
;
2352 GlDraw.color (1., 1., 1.);
2355 let l = String.length
s in
2358 let pan = pan * 2 in
2359 let left = l + pan in
2362 let s = String.sub
s (-pan) left in
2363 draw_string (float x) (float (y + 16)) s
2366 draw_string (float (x + pan*15)) (float (y + 16)) s
2378 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2379 GlDraw.viewport
margin 0 state.w conf.winh
;
2381 GlClear.color (scalecolor 0.5);
2382 GlClear.clear
[`
color];
2385 Gl.enable `scissor_test
;
2386 GlMisc.scissor
0 0 (conf.winw
- conf.scrollw
) conf.winh
;
2388 List.iter
drawpage state.layout;
2391 Gl.disable `scissor_test
2395 let x = -.float state.x in
2396 GlMat.translate ~
x ();
2400 GlDraw.viewport
0 0 conf.winw
conf.winh
;
2405 Glut.swapBuffers
();
2409 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2410 let x = x - margin - state.x in
2411 let rec f = function
2413 begin match getopaque l.pageno with
2414 | Some
(opaque, _
) when validopaque opaque ->
2415 let y = y - l.pagedispy
in
2418 let y = l.pagey + y in
2419 let x = x - l.pagex
in
2420 match whatsunder
opaque x y with
2433 let viewmouse button bstate
x y =
2435 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2436 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2438 match state.mstate
with
2439 | Mzoom
(oldn
, i) ->
2447 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
2449 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
2451 let zoom = conf.zoom +. incr in
2453 state.mstate
<- Mzoom
(n, 0);
2455 state.mstate
<- Mzoom
(n, i+1);
2457 else state.mstate
<- Mzoom
(n, 0)
2459 | _
-> state.mstate
<- Mzoom
(n, 0)
2462 if state.ascrollstep
> 0
2464 setautoscrollspeed (n=4)
2468 then -conf.scrollstep
2469 else conf.scrollstep
2471 let incr = incr * 2 in
2472 let y = clamp incr in
2473 gotoy_and_clear_text y
2476 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
2477 if bstate
= Glut.DOWN
2479 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
2480 state.mstate
<- Mpan
(x, y)
2483 state.mstate
<- Mnone
2485 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollw
->
2486 if bstate
= Glut.DOWN
2488 let position, sh = scrollph state.y in
2489 if y > truncate
position && y < truncate
(position +. sh)
2491 state.mstate
<- Mscroll
2493 let percent = float y /. float conf.winh
in
2494 let desty = truncate
(float (state.maxy - conf.winh
) *. percent) in
2496 state.mstate
<- Mscroll
2498 state.mstate
<- Mnone
2500 | Glut.LEFT_BUTTON
->
2501 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
2502 begin match dest with
2503 | Ulinkgoto
(pageno, top) ->
2507 gotopage1 pageno top;
2513 | Unone
when bstate
= Glut.DOWN
->
2514 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
2515 state.mstate
<- Mpan
(x, y);
2517 | Unone
| Utext _
->
2518 if bstate
= Glut.DOWN
2520 if conf.angle
mod 360 = 0
2522 state.mstate
<- Msel
((x, y), (x, y));
2523 Glut.postRedisplay
()
2527 match state.mstate
with
2530 | Mzoom _
| Mscroll
->
2531 state.mstate
<- Mnone
2534 Glut.setCursor
Glut.CURSOR_INHERIT
;
2535 state.mstate
<- Mnone
2537 | Msel
((x0
, y0
), (x1
, y1
)) ->
2539 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
2540 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
2542 match getopaque l.pageno with
2543 | Some
(opaque, _
) when validopaque opaque ->
2547 List.iter
f state.layout;
2548 copysel
""; (* ugly *)
2549 Glut.setCursor
Glut.CURSOR_INHERIT
;
2550 state.mstate
<- Mnone
;
2557 let birdseyemouse button bstate
x y
2558 (conf, leftx
, pageno, hooverpageno
, anchor) =
2560 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2561 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2562 let rec loop = function
2565 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
2566 && x > margin && x < margin + l.pagew
2568 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
2573 | Glut.OTHER_BUTTON _
-> viewmouse button bstate
x y
2577 let mouse bstate button
x y =
2578 match state.mode
with
2579 | View
-> viewmouse button bstate
x y
2580 | Birdseye beye
-> birdseyemouse button bstate
x y beye
2585 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
2588 match state.mode
with
2591 match state.mstate
with
2592 | Mzoom _
| Mnone
-> ()
2597 state.mstate
<- Mpan
(x, y);
2598 if conf.zoom > 1.0 then state.x <- state.x + dx;
2600 gotoy_and_clear_text y
2603 state.mstate
<- Msel
(a, (x, y));
2604 Glut.postRedisplay
()
2607 let y = min
conf.winh
(max
0 y) in
2608 let percent = float y /. float conf.winh
in
2609 let y = truncate
(float (state.maxy - conf.winh
) *. percent) in
2610 gotoy_and_clear_text y
2614 match state.mode
with
2615 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
2616 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2617 let rec loop = function
2619 if hooverpageno
!= -1
2621 state.mode
<- Birdseye
(conf, leftx
, pageno, -1, anchor);
2622 Glut.postRedisplay
();
2625 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
2626 && x > margin && x < margin + l.pagew
2628 state.mode
<- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
2629 Glut.postRedisplay
();
2637 match state.mstate
with
2639 begin match getunder x y with
2640 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
2642 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
2643 Glut.setCursor
Glut.CURSOR_INFO
2644 | Ulinkgoto
(page
, y) ->
2646 then showtext 'p'
("age: " ^ string_of_int page
);
2647 Glut.setCursor
Glut.CURSOR_INFO
2649 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
2650 Glut.setCursor
Glut.CURSOR_TEXT
2653 | Mpan _
| Msel _
| Mzoom _
| Mscroll
->
2664 match Sys.os_type
with
2665 | "Win32" -> Sys.getenv
"HOMEPATH"
2666 | _
-> Sys.getenv
"HOME"
2669 ("Can not determine home directory location: " ^
2670 Printexc.to_string exn
);
2674 let config_of c attrs
=
2678 | "scroll-bar-width" -> { c with scrollw
= max
0 (int_of_string v
) }
2679 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string v
) }
2680 | "case-insensitive-search" -> { c with icase
= bool_of_string v
}
2681 | "preload" -> { c with preload = bool_of_string v
}
2682 | "page-bias" -> { c with pagebias
= int_of_string v
}
2683 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string v
) }
2684 | "auto-scroll-step" ->
2685 { c with autoscrollstep = max
0 (int_of_string v
) }
2686 | "max-height-fit" -> { c with maxhfit
= bool_of_string v
}
2687 | "crop-hack" -> { c with crophack
= bool_of_string v
}
2688 | "throttle" -> { c with showall
= bool_of_string v
}
2689 | "highlight-links" -> { c with hlinks
= bool_of_string v
}
2690 | "under-cursor-info" -> { c with underinfo
= bool_of_string v
}
2691 | "vertical-margin" ->
2692 { c with interpagespace = max
0 (int_of_string v
) }
2694 let zoom = float_of_string v
/. 100. in
2695 let zoom = max
0.01 (min
2.2 zoom) in
2696 { c with zoom = zoom }
2697 | "presentation" -> { c with presentation = bool_of_string v
}
2698 | "rotation-angle" -> { c with angle
= int_of_string v
}
2699 | "width" -> { c with winw
= max
20 (int_of_string v
) }
2700 | "height" -> { c with winh
= max
20 (int_of_string v
) }
2701 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string v
}
2702 | "proportional-display" -> { c with proportional
= bool_of_string v
}
2703 | "pixmap-cache-size" -> { c with memlimit
= max
2 (int_of_string v
) }
2704 | "tex-count" -> { c with texcount
= max
1 (int_of_string v
) }
2705 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string v
) }
2706 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string v
) }
2707 | "persistent-location" -> { c with jumpback
= bool_of_string v
}
2710 prerr_endline
("Error processing attribute (`" ^
2711 k ^
"'=`" ^ v ^
"'): " ^
Printexc.to_string exn
);
2714 let rec fold c = function
2717 let c = apply c k v
in
2723 let fromstring f pos
n v
d =
2726 dolog "Error processing attribute (%S=%S) at %d\n%s"
2727 n v pos
(Printexc.to_string exn
)
2732 let bookmark_of attrs
=
2733 let rec fold title page rely
= function
2734 | ("title", v
) :: rest
-> fold v page rely rest
2735 | ("page", v
) :: rest
-> fold title v rely rest
2736 | ("rely", v
) :: rest
-> fold title page v rest
2737 | _
:: rest
-> fold title page rely rest
2738 | [] -> title, page
, rely
2740 fold "invalid" "0" "0" attrs
2744 let rec fold path page rely
pan = function
2745 | ("path", v
) :: rest
-> fold v page rely
pan rest
2746 | ("page", v
) :: rest
-> fold path v rely
pan rest
2747 | ("rely", v
) :: rest
-> fold path page v
pan rest
2748 | ("pan", v
) :: rest
-> fold path page rely v rest
2749 | _
:: rest
-> fold path page rely
pan rest
2750 | [] -> path
, page
, rely
, pan
2752 fold "" "0" "0" "0" attrs
2755 let setconf dst src
=
2756 dst
.scrollw
<- src
.scrollw
;
2757 dst
.scrollh
<- src
.scrollh
;
2758 dst
.icase
<- src
.icase
;
2759 dst
.preload <- src
.preload;
2760 dst
.pagebias
<- src
.pagebias
;
2761 dst
.verbose
<- src
.verbose
;
2762 dst
.scrollstep
<- src
.scrollstep
;
2763 dst
.maxhfit
<- src
.maxhfit
;
2764 dst
.crophack
<- src
.crophack
;
2765 dst
.autoscrollstep <- src
.autoscrollstep;
2766 dst
.showall
<- src
.showall
;
2767 dst
.hlinks
<- src
.hlinks
;
2768 dst
.underinfo
<- src
.underinfo
;
2769 dst
.interpagespace <- src
.interpagespace;
2770 dst
.zoom <- src
.zoom;
2771 dst
.presentation <- src
.presentation;
2772 dst
.angle
<- src
.angle
;
2773 dst
.winw
<- src
.winw
;
2774 dst
.winh
<- src
.winh
;
2775 dst
.savebmarks
<- src
.savebmarks
;
2776 dst
.memlimit
<- src
.memlimit
;
2777 dst
.proportional
<- src
.proportional
;
2778 dst
.texcount
<- src
.texcount
;
2779 dst
.sliceheight
<- src
.sliceheight
;
2780 dst
.thumbw
<- src
.thumbw
;
2781 dst
.jumpback
<- src
.jumpback
;
2785 let l = String.length
s in
2786 let b = Buffer.create
l in
2792 let h = Hashtbl.create
10 in
2793 let dc = { defconf with angle
= defconf.angle
} in
2794 let rec toplevel v t spos epos
=
2796 | Vdata
| Vcdata
| Vend
-> v
2797 | Vopen
("llppconfig", attrs
, closed
) ->
2800 else { v
with f = llppconfig
}
2802 error
"unexpected subelement at top level" s spos
2803 | Vclose tag
-> error
"unexpected close at top level" s spos
2805 and llppconfig v t spos epos
=
2807 | Vdata
| Vcdata
| Vend
-> v
2808 | Vopen
("defaults", attrs
, closed
) ->
2809 let c = config_of dc attrs
in
2813 else { v
with f = skip
"defaults" (fun () -> v
) }
2815 | Vopen
("doc", attrs
, closed
) ->
2816 let pathent, spage
, srely
, span
= doc_of attrs
in
2817 let path = unent pathent
2818 and pageno = fromstring int_of_string spos
"page" spage
0
2819 and rely
= fromstring float_of_string spos
"rely" srely
0.0
2820 and pan = fromstring int_of_string spos
"pan" span
0 in
2821 let c = config_of dc attrs
in
2822 let anchor = (pageno, rely
) in
2824 then (Hashtbl.add
h path (c, [], pan, anchor); v
)
2825 else { v
with f = doc
path pan anchor c [] }
2827 | Vopen
(tag
, _
, closed
) ->
2828 error
"unexpected subelement in llppconfig" s spos
2830 | Vclose
"llppconfig" -> { v
with f = toplevel }
2831 | Vclose tag
-> error
"unexpected close in llppconfig" s spos
2833 and doc
path pan anchor c bookmarks v t spos epos
=
2835 | Vdata
| Vcdata
-> v
2836 | Vend
-> error
"unexpected end of input in doc" s spos
2837 | Vopen
("bookmarks", attrs
, closed
) ->
2838 { v
with f = pbookmarks
path pan anchor c bookmarks }
2840 | Vopen
(tag
, _
, _
) ->
2841 error
"unexpected subelement in doc" s spos
2844 Hashtbl.add
h path (c, List.rev
bookmarks, pan, anchor);
2845 { v
with f = llppconfig
}
2847 | Vclose tag
-> error
"unexpected close in doc" s spos
2849 and pbookmarks
path pan anchor c bookmarks v t spos epos
=
2851 | Vdata
| Vcdata
-> v
2852 | Vend
-> error
"unexpected end of input in bookmarks" s spos
2853 | Vopen
("item", attrs
, closed
) ->
2854 let titleent, spage
, srely
= bookmark_of attrs
in
2855 let page = fromstring int_of_string spos
"page" spage
0
2856 and rely
= fromstring float_of_string spos
"rely" srely
0.0 in
2857 let bookmarks = (unent titleent, 0, page, rely
) :: bookmarks in
2859 then { v
with f = pbookmarks
path pan anchor c bookmarks }
2862 { v
with f = skip
"item" f }
2865 error
"unexpected subelement in bookmarks" s spos
2867 | Vclose
"bookmarks" ->
2868 { v
with f = doc
path pan anchor c bookmarks }
2870 | Vclose tag
-> error
"unexpected close in bookmarks" s spos
2872 and skip tag
f v t spos epos
=
2874 | Vdata
| Vcdata
-> v
2876 error
("unexpected end of input in skipped " ^ tag
) s spos
2877 | Vopen
(tag'
, _
, closed
) ->
2881 let f'
() = { v
with f = skip tag
f } in
2882 { v
with f = skip tag'
f'
}
2886 else error
("unexpected close in skipped " ^ tag
) s spos
2889 parse
{ f = toplevel; accu = () } s;
2895 let len = in_channel_length ic
in
2896 let s = String.create
len in
2897 really_input ic
s 0 len;
2900 | Parse_error
(msg
, s, pos
) ->
2901 let subs = subs s pos
in
2902 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
2903 failwith
("parse error: " ^
s)
2906 failwith
("config load error: " ^
Printexc.to_string exn
)
2912 let dir = Filename.concat
home ".config" in
2913 if Sys.is_directory
dir then dir else home
2916 Filename.concat
dir "llpp.conf"
2920 if Sys.file_exists
path
2923 (try Some
(open_in_bin
path)
2926 ("Error opening configuation file `" ^
path ^
"': " ^
2927 Printexc.to_string exn
);
2936 ("Error loading configuation from `" ^
path ^
"': " ^
2937 Printexc.to_string exn
);
2943 f (Hashtbl.create
0, defconf)
2948 let pc, pb
, px
, pa
=
2950 Hashtbl.find
h (Filename.basename
state.path)
2951 with Not_found
-> dc, [], 0, (0, 0.0)
2955 state.bookmarks <- pb
;
2958 then state.anchor <- pa
2959 else cbput state.hists
.nav pa
;
2964 let add_attrs bb always
dc c =
2967 then Printf.bprintf bb
"\n %s='%b'" s a
2970 then Printf.bprintf bb
"\n %s='%d'" s a
2973 then Printf.bprintf bb
"\n %s='%f'" s (a*.100.)
2977 then dc.winw
, dc.winh
2979 match state.fullscreen
with
2981 | None
-> c.winw
, c.winh
2983 let zoom, presentation, interpagespace, showall
=
2985 then dc.zoom, dc.presentation, dc.interpagespace, dc.showall
2987 match state.mode
with
2988 | Birdseye
(bc
, _
, _
, _
, _
) ->
2989 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.showall
2990 | _
-> c.zoom, c.presentation, c.interpagespace, c.showall
2992 oi
"width" w dc.winw
;
2993 oi
"height" h dc.winh
;
2994 oi
"scroll-bar-width" c.scrollw
dc.scrollw
;
2995 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
2996 ob "case-insensitive-search" c.icase
dc.icase
;
2997 ob "preload" c.preload dc.preload;
2998 oi
"page-bias" c.pagebias
dc.pagebias
;
2999 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
3000 oi
"auto-scroll-step" c.autoscrollstep dc.autoscrollstep;
3001 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
3002 ob "crop-hack" c.crophack
dc.crophack
;
3003 ob "throttle" showall
dc.showall
;
3004 ob "highlight-links" c.hlinks
dc.hlinks
;
3005 ob "under-cursor-info" c.underinfo
dc.underinfo
;
3006 oi
"vertical-margin" interpagespace dc.interpagespace;
3007 oz
"zoom" zoom dc.zoom;
3008 ob "presentation" presentation dc.presentation;
3009 oi
"rotation-angle" c.angle
dc.angle
;
3010 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
3011 ob "proportional-display" c.proportional
dc.proportional
;
3012 oi
"pixmap-cache-size" c.memlimit
dc.memlimit
;
3013 oi
"texcount" c.texcount
dc.texcount
;
3014 oi
"slice-height" c.sliceheight
dc.sliceheight
;
3015 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
3016 ob "persistent-location" c.jumpback
dc.jumpback
;
3020 let bb = Buffer.create
32768 in
3022 Buffer.add_string
bb "<llppconfig>\n<defaults ";
3023 add_attrs bb true dc dc;
3024 Buffer.add_string
bb "/>\n";
3026 let adddoc path pan anchor c bookmarks =
3027 if bookmarks == [] && c = dc && anchor = emptyanchor
3030 Printf.bprintf
bb "<doc path='%s'"
3031 (enent
path 0 (String.length
path));
3033 if anchor <> emptyanchor
3035 let n, y = anchor in
3036 Printf.bprintf
bb " page='%d'" n;
3039 Printf.bprintf
bb " rely='%f'" y
3044 then Printf.bprintf
bb " pan='%d'" pan;
3046 add_attrs bb false dc c;
3048 begin match bookmarks with
3049 | [] -> Buffer.add_string
bb "/>\n"
3051 Buffer.add_string
bb ">\n<bookmarks>\n";
3052 List.iter
(fun (title, _level
, page, rely
) ->
3054 "<item title='%s' page='%d'"
3055 (enent
title 0 (String.length
title))
3060 Printf.bprintf
bb " rely='%f'" rely
3062 Buffer.add_string
bb "/>\n";
3064 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
3070 match state.mode
with
3071 | Birdseye
(_
, pan, _
, _
, _
) -> pan
3074 let basename = Filename.basename state.path in
3075 adddoc basename pan (getanchor ())
3078 if state.ascrollstep
> 0
3079 then state.ascrollstep
3080 else conf.autoscrollstep }
3081 (if conf.savebmarks
then state.bookmarks else []);
3083 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
3085 then adddoc path x y c bookmarks
3087 Buffer.add_string
bb "</llppconfig>";
3090 if Buffer.length
bb > 0
3093 let tmp = path ^
".tmp" in
3094 let oc = open_out_bin
tmp in
3095 Buffer.output_buffer
oc bb;
3097 Sys.rename
tmp path;
3100 ("error while saving configuration: " ^
Printexc.to_string exn
)
3107 ["-p", Arg.String
(fun s -> state.password
<- s) , " Set password"
3108 ;("-v", Arg.Unit
(fun () -> print_endline
Help.version
; exit
0),
3109 " Print version and exit")]
3111 (fun s -> state.path <- s)
3112 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
3114 if String.length
state.path = 0
3115 then (prerr_endline
"file name missing"; exit
1);
3119 let _ = Glut.init
Sys.argv
in
3120 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
3121 let () = Glut.initWindowSize
conf.winw
conf.winh
in
3122 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
3125 if Sys.os_type
= "Unix"
3127 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
3129 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
3130 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
3131 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
3132 Unix.bind
sock addr;
3134 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
3135 Unix.connect
csock addr;
3136 let ssock, _ = Unix.accept
sock in
3139 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
3140 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
3144 at_exit
(fun () -> Unix.shutdown
ssock Unix.SHUTDOWN_ALL
);
3148 let () = Glut.displayFunc
display in
3149 let () = Glut.reshapeFunc
reshape in
3150 let () = Glut.keyboardFunc
keyboard in
3151 let () = Glut.specialFunc
special in
3152 let () = Glut.idleFunc
(Some
idle) in
3153 let () = Glut.mouseFunc
mouse in
3154 let () = Glut.motionFunc
motion in
3155 let () = Glut.passiveMotionFunc
pmotion in
3157 init
ssock (conf.angle
, conf.proportional
, conf.texcount
, conf.sliceheight
);
3158 state.csock <- csock;
3159 state.ssock <- ssock;
3160 state.text <- "Opening " ^
state.path;
3161 writeopen state.path state.password
;
3165 let rec handlelablglutbug () =
3168 with Glut.BadEnum
"key in special_of_int" ->
3169 showtext '
!'
" LablGlut bug: special key not recognized";
3170 handlelablglutbug ()
3172 handlelablglutbug ();