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, "version " ^
Help.version
)
1307 :: (1, "presentation mode " ^
btos conf.presentation)
1308 :: (1, "case insensitive search " ^
btos conf.icase
)
1309 :: (1, "preload " ^
btos conf.preload)
1310 :: (1, "page bias " ^ string_of_int
conf.pagebias
)
1311 :: (1, "verbose " ^
btos conf.verbose
)
1312 :: (1, "scroll step " ^ string_of_int
conf.scrollstep
)
1313 :: (1, "max fit " ^
btos conf.maxhfit
)
1314 :: (1, "crop hack " ^
btos conf.crophack
)
1315 :: (1, "autoscroll step " ^ string_of_int
autoscrollstep)
1316 :: (1, "throttle " ^
btos conf.showall
)
1317 :: (1, "highlight links " ^
btos conf.hlinks
)
1318 :: (1, "under info " ^
btos conf.underinfo
)
1319 :: (1, "veritcal margin " ^ string_of_int
conf.interpagespace)
1320 :: (1, "zoom " ^
Printf.sprintf
"%-5.1f" (conf.zoom*.100.))
1321 :: (1, "rotation " ^ string_of_int
conf.angle
)
1322 :: (1, "persistent bookmarks " ^
btos conf.savebmarks
)
1323 :: (1, "proportional display " ^
btos conf.proportional
)
1324 :: (1, "pixmap cache size " ^ string_of_int
conf.memlimit
)
1325 :: (1, "pixmap cache used " ^ string_of_int
state.memused
)
1326 :: (1, "thumbnail width " ^ string_of_int
conf.thumbw
)
1327 :: (1, "persistent location " ^
btos conf.jumpback
)
1328 :: (1, Printf.sprintf
"window dimensions %dx%d " conf.winw
conf.winh
)
1329 :: (0, "Document information")
1330 :: (1, string_of_int
state.pagecount ^
" pages")
1334 let o = Array.create
(List.length
info) ("", 0, pageno, top) in
1335 let rec iteri i
= function
1338 o.(i
) <- (s, l, pageno, top);
1344 enterselector false o "Info not available" "";
1347 let enterhelpmode () =
1348 let pageno, top = getanchor () in
1350 let help = ("Keys for llpp " ^
Help.version
) ::state.help in
1351 let o = Array.create
(List.length
help) ("", 0, pageno, top) in
1352 let rec iteri i
= function
1355 o.(i
) <- (s, (if i
= 0 then 0 else 1), pageno, top);
1361 enterselector false o "Help not available" "";
1364 let quickbookmark ?title
() =
1365 match state.layout with
1371 let sec = Unix.gettimeofday
() in
1372 let tm = Unix.localtime
sec in
1373 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
1377 (tm.Unix.tm_year
+ 1900)
1380 | Some
title -> title
1383 (title, 0, l.pageno, float l.pagey /. float l.pageh
) :: state.bookmarks
1387 state.fullscreen
<- None
;
1388 Glut.reshapeWindow
w h;
1391 let writeopen path password
=
1392 writecmd state.csock
("open " ^ path ^
"\000" ^
state.password ^
"\000");
1393 writecmd state.csock
"info";
1396 let opendoc path password
=
1399 state.password
<- password
;
1400 state.gen
<- state.gen
+ 1;
1402 writeopen path password
;
1403 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1404 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1407 let viewkeyboard ~key ~x ~
y =
1409 state.mode
<- Textentry
(te
, state.mode
);
1412 Glut.postRedisplay
()
1414 let c = Char.chr key
in
1420 let y = getnav () in
1421 gotoy_and_clear_text y
1429 Glut.postRedisplay
()
1432 let ondone isforw
s =
1433 cbput state.hists
.pat
s;
1434 state.searchpattern
<- s;
1437 enttext (c, "", Some
(onhist state.hists
.pat
),
1438 textentry, ondone (c ='
/'
))
1440 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
1441 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
1442 setzoom (min
2.2 (conf.zoom +. incr))
1447 try int_of_string
s with exc
->
1448 state.text <- Printf.sprintf
"bad integer `%s': %s"
1449 s (Printexc.to_string exc
);
1455 state.text <- "page bias is now " ^ string_of_int
n;
1458 enttext ('
+'
, "", None
, intentry, ondone)
1460 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
1461 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
1462 setzoom (max
0.01 (conf.zoom -. decr))
1468 enttext ('
-'
, "", None
, optentry, ondone)
1470 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1473 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1474 let zoom = zoomforh
conf.winw
conf.winh
conf.scrollw
in
1478 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1484 try int_of_string
s with exc
->
1485 state.text <- Printf.sprintf
"bad integer `%s': %s"
1486 s (Printexc.to_string exc
);
1492 cbput state.hists
.pag
(string_of_int
n);
1493 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
1496 let pageentry text key
=
1497 match Char.unsafe_chr key
with
1498 | 'g'
-> TEdone
text
1499 | _
-> intentry text key
1501 let text = "x" in text.[0] <- c;
1502 enttext ('
:'
, text, Some
(onhist state.hists
.pag
), pageentry, ondone)
1505 conf.scrollw
<- if conf.scrollw
> 0 then 0 else defconf.scrollw
;
1506 reshape conf.winw
conf.winh
;
1509 conf.hlinks
<- not
conf.hlinks
;
1510 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
1511 Glut.postRedisplay
()
1514 if state.ascrollstep
= 0
1515 then state.ascrollstep
<- conf.autoscrollstep
1517 conf.autoscrollstep <- state.ascrollstep
;
1518 state.ascrollstep
<- 0;
1522 conf.presentation <- not
conf.presentation;
1523 showtext ' '
("presentation mode " ^
1524 if conf.presentation then "on" else "off");
1525 state.anchor <- getanchor ();
1529 begin match state.fullscreen
with
1531 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
1534 state.fullscreen
<- None
;
1539 gotoy_and_clear_text 0
1542 search state.searchpattern
true
1545 search state.searchpattern
false
1548 begin match state.layout with
1551 gotoy_and_clear_text (getpagey l.pageno)
1555 begin match List.rev
state.layout with
1558 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
1559 gotoy_and_clear_text (getpagey pageno)
1563 begin match state.layout with
1566 let pageno = max
0 (l.pageno-1) in
1567 gotoy_and_clear_text (getpagey pageno)
1572 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
1574 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
1576 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
1580 else (100. *. (float state.y /. float maxy)) in
1583 Printf.sprintf
"Page %d of %d %.2f%%"
1584 (fn+1) state.pagecount
percent
1587 "Pages %d-%d of %d %.2f%%"
1588 (fn+1) (ln
+1) state.pagecount
percent
1593 begin match state.layout with
1596 doreshape (l.pagew
+ conf.scrollw
) l.pageh
;
1597 Glut.postRedisplay
();
1601 enterbookmarkmode ()
1611 match state.layout with
1614 (s, 0, l.pageno, float l.pagey /. float l.pageh
)
1618 enttext ('~'
, "", None
, textentry, ondone)
1622 showtext ' '
"Quick bookmark added";
1625 begin match state.layout with
1627 let rect = getpdimrect
l.pagedimno
in
1631 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
1632 truncate
(1.2 *. (rect.(3) -. rect.(0))))
1634 (truncate
(rect.(1) -. rect.(0)),
1635 truncate
(rect.(3) -. rect.(0)))
1639 doreshape (w + conf.scrollw
) (h + conf.interpagespace)
1641 Glut.postRedisplay
();
1647 reinit (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
1652 (min
(state.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 1.0);
1653 Glut.postRedisplay
()
1655 | 'k'
-> gotoy (clamp (-conf.scrollstep
))
1656 | 'j'
-> gotoy (clamp conf.scrollstep
)
1658 | '
r'
-> opendoc state.path
state.password
1661 vlog "huh? %d %c" key
(Char.chr key
);
1664 let textentrykeyboard ~key ~x ~
y ((c, text, opthist
, onkey
, ondone), mode
) =
1666 state.mode
<- Textentry
(te
, mode
);
1669 Glut.postRedisplay
()
1671 match Char.unsafe_chr key
with
1673 let len = String.length
text in
1677 Glut.postRedisplay
();
1680 let s = String.sub
text 0 (len - 1) in
1681 enttext (c, s, opthist
, onkey
, ondone)
1687 Glut.postRedisplay
()
1690 begin match opthist
with
1692 | Some
(_
, onhistcancel
) -> onhistcancel
()
1695 Glut.postRedisplay
()
1698 begin match onkey
text key
with
1702 Glut.postRedisplay
()
1705 enttext (c, text, opthist
, onkey
, ondone);
1709 Glut.postRedisplay
()
1712 state.mode
<- Textentry
(te
, mode
);
1713 Glut.postRedisplay
()
1717 let birdseyekeyboard ~key ~x ~
y ((_
, _
, pageno, _
, anchor) as beye
) =
1720 leavebirdseye beye
true
1723 let y, h = getpageyh pageno in
1724 let top = (conf.winh
- h) / 2 in
1725 gotoy (max
0 (y - top))
1728 leavebirdseye beye
false
1731 viewkeyboard ~key ~x ~
y
1734 let outlinekeyboard ~key ~x ~
y
1735 (allowdel
, active, first
, outlines, qsearch
, pan
) =
1736 let narrow outlines pattern
=
1737 let reopt = try Some
(Str.regexp_case_fold pattern
) with _
-> None
in
1741 let rec fold accu n =
1745 let (s, _
, _
, _
) as o = outlines.(n) in
1747 if (try ignore
(Str.search_forward re
s 0); true
1748 with Not_found
-> false)
1754 let matched = fold [] (Array.length
outlines - 1) in
1755 if matched = [] then None
else Some
(Array.of_list
matched)
1757 let search active pattern
incr =
1760 if n = Array.length
outlines || n = -1
1763 let (s, _
, _
, _
) = outlines.(n) in
1765 (try ignore
(Str.search_forward re
s 0); true
1766 with Not_found
-> false)
1768 else loop (n + incr)
1773 let re = Str.regexp_case_fold pattern
in
1779 let firstof active = max
0 (active - maxoutlinerows () / 2) in
1782 if String.length qsearch
= 0
1786 Glut.postRedisplay
();
1790 state.mode
<- Outline
(allowdel
, active, first
, outlines, "", pan
);
1791 Glut.postRedisplay
();
1795 let incr = if key
= 18 then -1 else 1 in
1797 match search (active + incr) qsearch
incr with
1799 state.text <- qsearch ^
" [not found]";
1802 state.text <- qsearch
;
1803 active, firstof active
1805 state.mode
<- Outline
(allowdel
, active, first
, outlines, qsearch
, pan
);
1806 Glut.postRedisplay
();
1809 let len = String.length qsearch
in
1816 state.mode
<- Outline
(allowdel
, active, first
, outlines, "", pan
);
1819 let qsearch = String.sub
qsearch 0 (len - 1) in
1821 match search active qsearch ~
-1 with
1823 state.text <- qsearch ^
" [not found]";
1826 state.text <- qsearch;
1827 active, firstof active
1829 state.mode
<- Outline
(allowdel
, active, first
, outlines, qsearch, pan
);
1831 Glut.postRedisplay
()
1834 if active < Array.length
outlines
1836 let (_
, _
, n, t
) = outlines.(active) in
1841 if allowdel
then state.bookmarks <- Array.to_list
outlines;
1843 Glut.postRedisplay
();
1845 | _
when key
>= 32 && key
< 127 ->
1846 let pattern = addchar qsearch (Char.chr key
) in
1848 match search active pattern 1 with
1850 state.text <- pattern ^
" [not found]";
1853 state.text <- pattern;
1854 active, firstof active
1856 state.mode
<- Outline
(allowdel
, active, first
, outlines, pattern, pan
);
1857 Glut.postRedisplay
()
1859 | 14 when not allowdel
-> (* ctrl-n *)
1860 if String.length
qsearch > 0
1862 let optoutlines = narrow outlines qsearch in
1863 begin match optoutlines with
1864 | None
-> state.text <- "can't narrow"
1866 state.mode
<- Outline
(allowdel
, 0, 0, outlines, qsearch, pan
);
1867 match state.outlines with
1870 state.outlines <- Onarrow
(qsearch, outlines, a)
1871 | Onarrow
(pat
, a, b) ->
1872 state.outlines <- Onarrow
(qsearch, outlines, b)
1875 Glut.postRedisplay
()
1877 | 21 when not allowdel
-> (* ctrl-u *)
1879 match state.outlines with
1882 let a = Array.of_list
(List.rev
l) in
1883 state.outlines <- Oarray
a;
1885 | Onarrow
(pat
, a, b) ->
1886 state.outlines <- Oarray
b;
1890 state.mode
<- Outline
(allowdel
, 0, 0, outline, qsearch, pan
);
1891 Glut.postRedisplay
()
1894 state.mode
<- Outline
1895 (allowdel
, active, firstof active, outlines, qsearch, pan
);
1896 Glut.postRedisplay
()
1898 | 127 when allowdel
->
1899 let len = Array.length
outlines - 1 in
1903 state.bookmarks <- [];
1906 let bookmarks = Array.init
len
1908 let i = if i >= active then i + 1 else i in
1921 Glut.postRedisplay
()
1923 | _
-> dolog "unknown key %d" key
1926 let keyboard ~key ~x ~
y =
1931 match state.mode
with
1932 | Outline
outline -> outlinekeyboard ~key ~x ~
y outline
1933 | Textentry
textentry -> textentrykeyboard ~key ~x ~
y textentry
1934 | Birdseye birdseye
-> birdseyekeyboard ~key ~x ~
y birdseye
1935 | View
-> viewkeyboard ~key ~x ~
y
1938 let birdseyespecial key x
y (conf, leftx
, pageno, hooverpageno
, anchor) =
1941 let pageno = max
0 (pageno - 1) in
1942 let rec loop = function
1943 | [] -> gotopage1 pageno 0
1944 | l :: _
when l.pageno = pageno ->
1945 if l.pagedispy
>= 0 && l.pagey = 0
1946 then Glut.postRedisplay
()
1947 else gotopage1 pageno 0
1948 | _
:: rest
-> loop rest
1951 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
1954 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
1955 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
1956 let rec loop = function
1958 let y, h = getpageyh pageno in
1959 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
1961 | l :: rest
when l.pageno = pageno ->
1962 if l.pagevh != l.pageh
1963 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
1964 else Glut.postRedisplay
()
1965 | l :: rest
-> loop rest
1969 | Glut.KEY_PAGE_UP
->
1970 begin match state.layout with
1974 state.mode
<- Birdseye
(
1975 conf, leftx
, l.pageno, hooverpageno
, anchor
1977 gotopage1 l.pageno 0;
1980 let layout = layout (state.y-conf.winh
) conf.winh
in
1982 | [] -> gotoy (clamp (-conf.winh
))
1984 state.mode
<- Birdseye
(
1985 conf, leftx
, l.pageno, hooverpageno
, anchor
1987 gotopage1 l.pageno 0
1990 | [] -> gotoy (clamp (-conf.winh
))
1993 | Glut.KEY_PAGE_DOWN
->
1994 begin match List.rev
state.layout with
1996 let layout = layout (state.y + conf.winh
) conf.winh
in
1997 begin match layout with
1999 let incr = l.pageh
- l.pagevh in
2004 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
2006 Glut.postRedisplay
();
2008 else gotoy (clamp (incr + conf.interpagespace*2));
2012 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
2013 gotopage1 l.pageno 0;
2016 | [] -> gotoy (clamp conf.winh
)
2020 state.mode
<- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
2024 let pageno = state.pagecount
- 1 in
2025 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2026 if not
(pagevisible state.layout pageno)
2029 match List.rev
state.pdims
with
2031 | (_
, _
, h, _
) :: _
-> h
2033 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
2034 else Glut.postRedisplay
();
2038 let setautoscrollspeed goingdown
=
2039 let incr = max
1 (state.ascrollstep
/ 2) in
2040 let astep = max
1 (state.ascrollstep
+ (if goingdown
then incr else -incr)) in
2041 state.ascrollstep
<- astep;
2044 let special ~key ~x ~
y =
2045 match state.mode
with
2046 | View
| (Birdseye _
) when key
= Glut.KEY_F9
->
2050 birdseyespecial key x
y vals
2052 | View
when key
= Glut.KEY_F1
->
2056 if state.ascrollstep
> 0 && (key
= Glut.KEY_DOWN
|| key
= Glut.KEY_UP
)
2057 then setautoscrollspeed (key
= Glut.KEY_DOWN
)
2061 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
2062 | Glut.KEY_UP
-> clamp (-conf.scrollstep
)
2063 | Glut.KEY_DOWN
-> clamp conf.scrollstep
2064 | Glut.KEY_PAGE_UP
->
2065 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2067 match state.layout with
2069 | l :: _
-> state.y - l.pagey
2072 | Glut.KEY_PAGE_DOWN
->
2073 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2075 match List.rev
state.layout with
2077 | l :: _
-> getpagey l.pageno
2080 | Glut.KEY_HOME
-> addnav (); 0
2083 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
2085 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
2086 state.x
<- state.x
- 10;
2088 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
2089 state.x
<- state.x
+ 10;
2094 gotoy_and_clear_text y
2097 ((c, s, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2100 | Glut.KEY_UP
-> action HCprev
2101 | Glut.KEY_DOWN
-> action HCnext
2102 | Glut.KEY_HOME
-> action HCfirst
2103 | Glut.KEY_END
-> action HClast
2106 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2107 Glut.postRedisplay
()
2111 | Outline
(allowdel
, active, first
, outlines, qsearch, pan
) ->
2112 let maxrows = maxoutlinerows () in
2113 let calcfirst first
active =
2116 let rows = active - first
in
2117 if rows > maxrows then active - maxrows else first
2121 let active = active + incr in
2122 let active = max
0 (min
active (Array.length
outlines - 1)) in
2123 let first = calcfirst first active in
2124 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch, pan
);
2125 Glut.postRedisplay
()
2127 let updownlevel incr =
2128 let len = Array.length
outlines in
2129 let (_
, curlevel
, _
, _
) = outlines.(active) in
2131 if i = len then i-1 else if i = -1 then 0 else
2132 let (_
, l, _
, _
) = outlines.(i) in
2133 if l != curlevel
then i else flow (i+incr)
2135 let active = flow active in
2136 let first = calcfirst first active in
2137 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch, pan
);
2138 Glut.postRedisplay
()
2141 | Glut.KEY_UP
-> navigate ~
-1
2142 | Glut.KEY_DOWN
-> navigate 1
2143 | Glut.KEY_PAGE_UP
-> navigate ~
-maxrows
2144 | Glut.KEY_PAGE_DOWN
-> navigate maxrows
2147 if Glut.active_ctrl
!= 0
2149 state.mode
<- Outline
(
2150 allowdel
, active, first, outlines, qsearch, min
0 (pan
+ 1)
2152 Glut.postRedisplay
();
2160 if Glut.active_ctrl
!= 0
2162 state.mode
<- Outline
(
2163 allowdel
, active, first, outlines, qsearch, pan
- 1
2165 Glut.postRedisplay
();
2169 then updownlevel ~
-1
2173 state.mode
<- Outline
(allowdel
, 0, 0, outlines, qsearch, pan
);
2174 Glut.postRedisplay
()
2177 let active = Array.length
outlines - 1 in
2178 let first = max
0 (active - maxrows) in
2179 state.mode
<- Outline
(
2180 allowdel
, active, first, outlines, qsearch, pan
2182 Glut.postRedisplay
()
2187 let drawplaceholder l =
2188 let margin = state.x
+ (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2190 (float l.pagex
, float l.pagedispy
)
2191 (float (l.pagew
+ l.pagex
), float (l.pagedispy
+ l.pagevh))
2193 let x = float (if margin < 0 then -margin else l.pagex
)
2194 and y = float (l.pagedispy
+ 13) in
2195 let font = Glut.BITMAP_8_BY_13
in
2196 GlDraw.color
(0.0, 0.0, 0.0);
2197 GlPix.raster_pos ~
x ~
y ();
2198 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c))
2199 ("Loading " ^ string_of_int
(l.pageno + 1));
2202 let now () = Unix.gettimeofday
();;
2206 match state.mode
with
2207 | Textentry _
-> scalecolor 0.4
2208 | View
| Outline _
-> scalecolor 1.0
2209 | Birdseye
(_
, _
, pageno, hooverpageno
, _
) ->
2210 if l.pageno = hooverpageno
2213 if l.pageno = pageno
2219 begin match getopaque l.pageno with
2220 | Some
(opaque, _
) when validopaque opaque ->
2222 draw
(l.pagedispy
, l.pagew
, l.pagevh, l.pagey, conf.hlinks
)
2226 vlog "draw %d %f sec" l.pageno d;
2234 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
2235 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2236 let sh = float conf.winh
/. sh in
2237 let sh = max
sh (float conf.scrollh
) in
2240 if state.y = state.maxy
2242 else float y /. float maxy
2244 let position = (float conf.winh
-. sh) *. percent in
2247 if position +. sh > float conf.winh
2248 then float conf.winh
-. sh
2254 let scrollindicator () =
2255 GlDraw.color (0.64 , 0.64, 0.64);
2257 (float (conf.winw
- conf.scrollw
), 0.)
2258 (float conf.winw
, float conf.winh
)
2260 GlDraw.color (0.0, 0.0, 0.0);
2262 let position, sh = scrollph state.y in
2264 (float (conf.winw
- conf.scrollw
), position)
2265 (float conf.winw
, position +. sh)
2269 let showsel margin =
2270 match state.mstate
with
2271 | Mnone
| Mscroll _
| Mpan _
| Mzoom _
->
2274 | Msel
((x0
, y0
), (x1
, y1
)) ->
2275 let rec loop = function
2277 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
2278 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
2280 match getopaque l.pageno with
2281 | Some
(opaque, _
) when validopaque opaque ->
2282 let oy = -l.pagey + l.pagedispy
in
2284 (x0
- margin - state.x, y0
,
2285 x1
- margin - state.x, y1
) oy;
2295 let panx = float state.x in
2297 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
2298 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2300 (fun (pageno, c, (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
2302 if l.pageno = pageno
2304 let d = float (l.pagedispy
- l.pagey) in
2305 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
2306 GlDraw.begins `quads
;
2308 GlDraw.vertex2
(x0
+.panx, y0
+.d);
2309 GlDraw.vertex2
(x1
+.panx, y1
+.d);
2310 GlDraw.vertex2
(x2
+.panx, y2
+.d);
2311 GlDraw.vertex2
(x3
+.panx, y3
+.d);
2321 let showoutline () =
2322 match state.mode
with
2323 | Outline
(allowdel
, active, first, outlines, qsearch, pan
) ->
2325 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2326 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2327 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2330 GlDraw.color (1., 1., 1.);
2331 let font = Glut.BITMAP_9_BY_15
in
2332 let draw_string x y s =
2333 GlPix.raster_pos ~
x ~
y ();
2334 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c)) s
2337 if row
= Array.length
outlines || (row
- first) * 16 > conf.winh
2340 let (s, l, _
, _
) = outlines.(row
) in
2341 let y = (row
- first) * 16 in
2346 GlDraw.polygon_mode `both `
line;
2347 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2348 GlDraw.color (1., 1., 1.) ~alpha
:0.9;
2349 GlDraw.rect (0., float (y + 1))
2350 (float (conf.winw
- 1), float (y + 18));
2351 GlDraw.polygon_mode `both `fill
;
2353 GlDraw.color (1., 1., 1.);
2356 let l = String.length
s in
2359 let pan = pan * 2 in
2360 let left = l + pan in
2363 let s = String.sub
s (-pan) left in
2364 draw_string (float x) (float (y + 16)) s
2367 draw_string (float (x + pan*15)) (float (y + 16)) s
2379 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2380 GlDraw.viewport
margin 0 state.w conf.winh
;
2382 GlClear.color (scalecolor 0.5);
2383 GlClear.clear
[`
color];
2386 Gl.enable `scissor_test
;
2387 GlMisc.scissor
0 0 (conf.winw
- conf.scrollw
) conf.winh
;
2389 List.iter
drawpage state.layout;
2392 Gl.disable `scissor_test
2396 let x = -.float state.x in
2397 GlMat.translate ~
x ();
2401 GlDraw.viewport
0 0 conf.winw
conf.winh
;
2406 Glut.swapBuffers
();
2410 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2411 let x = x - margin - state.x in
2412 let rec f = function
2414 begin match getopaque l.pageno with
2415 | Some
(opaque, _
) when validopaque opaque ->
2416 let y = y - l.pagedispy
in
2419 let y = l.pagey + y in
2420 let x = x - l.pagex
in
2421 match whatsunder
opaque x y with
2434 let viewmouse button bstate
x y =
2436 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2437 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2439 match state.mstate
with
2440 | Mzoom
(oldn
, i) ->
2448 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
2450 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
2452 let zoom = conf.zoom +. incr in
2454 state.mstate
<- Mzoom
(n, 0);
2456 state.mstate
<- Mzoom
(n, i+1);
2458 else state.mstate
<- Mzoom
(n, 0)
2460 | _
-> state.mstate
<- Mzoom
(n, 0)
2463 if state.ascrollstep
> 0
2465 setautoscrollspeed (n=4)
2469 then -conf.scrollstep
2470 else conf.scrollstep
2472 let incr = incr * 2 in
2473 let y = clamp incr in
2474 gotoy_and_clear_text y
2477 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
2478 if bstate
= Glut.DOWN
2480 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
2481 state.mstate
<- Mpan
(x, y)
2484 state.mstate
<- Mnone
2486 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollw
->
2487 if bstate
= Glut.DOWN
2489 let position, sh = scrollph state.y in
2490 if y > truncate
position && y < truncate
(position +. sh)
2492 state.mstate
<- Mscroll
2494 let percent = float y /. float conf.winh
in
2495 let desty = truncate
(float (state.maxy - conf.winh
) *. percent) in
2497 state.mstate
<- Mscroll
2499 state.mstate
<- Mnone
2501 | Glut.LEFT_BUTTON
->
2502 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
2503 begin match dest with
2504 | Ulinkgoto
(pageno, top) ->
2508 gotopage1 pageno top;
2514 | Unone
when bstate
= Glut.DOWN
->
2515 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
2516 state.mstate
<- Mpan
(x, y);
2518 | Unone
| Utext _
->
2519 if bstate
= Glut.DOWN
2521 if conf.angle
mod 360 = 0
2523 state.mstate
<- Msel
((x, y), (x, y));
2524 Glut.postRedisplay
()
2528 match state.mstate
with
2531 | Mzoom _
| Mscroll
->
2532 state.mstate
<- Mnone
2535 Glut.setCursor
Glut.CURSOR_INHERIT
;
2536 state.mstate
<- Mnone
2538 | Msel
((x0
, y0
), (x1
, y1
)) ->
2540 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
2541 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
2543 match getopaque l.pageno with
2544 | Some
(opaque, _
) when validopaque opaque ->
2548 List.iter
f state.layout;
2549 copysel
""; (* ugly *)
2550 Glut.setCursor
Glut.CURSOR_INHERIT
;
2551 state.mstate
<- Mnone
;
2558 let birdseyemouse button bstate
x y
2559 (conf, leftx
, pageno, hooverpageno
, anchor) =
2561 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2562 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2563 let rec loop = function
2566 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
2567 && x > margin && x < margin + l.pagew
2569 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
2574 | Glut.OTHER_BUTTON _
-> viewmouse button bstate
x y
2578 let mouse bstate button
x y =
2579 match state.mode
with
2580 | View
-> viewmouse button bstate
x y
2581 | Birdseye beye
-> birdseyemouse button bstate
x y beye
2586 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
2589 match state.mode
with
2592 match state.mstate
with
2593 | Mzoom _
| Mnone
-> ()
2598 state.mstate
<- Mpan
(x, y);
2599 if conf.zoom > 1.0 then state.x <- state.x + dx;
2601 gotoy_and_clear_text y
2604 state.mstate
<- Msel
(a, (x, y));
2605 Glut.postRedisplay
()
2608 let y = min
conf.winh
(max
0 y) in
2609 let percent = float y /. float conf.winh
in
2610 let y = truncate
(float (state.maxy - conf.winh
) *. percent) in
2611 gotoy_and_clear_text y
2615 match state.mode
with
2616 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
2617 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2618 let rec loop = function
2620 if hooverpageno
!= -1
2622 state.mode
<- Birdseye
(conf, leftx
, pageno, -1, anchor);
2623 Glut.postRedisplay
();
2626 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
2627 && x > margin && x < margin + l.pagew
2629 state.mode
<- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
2630 Glut.postRedisplay
();
2638 match state.mstate
with
2640 begin match getunder x y with
2641 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
2643 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
2644 Glut.setCursor
Glut.CURSOR_INFO
2645 | Ulinkgoto
(page
, y) ->
2647 then showtext 'p'
("age: " ^ string_of_int page
);
2648 Glut.setCursor
Glut.CURSOR_INFO
2650 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
2651 Glut.setCursor
Glut.CURSOR_TEXT
2654 | Mpan _
| Msel _
| Mzoom _
| Mscroll
->
2665 match Sys.os_type
with
2666 | "Win32" -> Sys.getenv
"HOMEPATH"
2667 | _
-> Sys.getenv
"HOME"
2670 ("Can not determine home directory location: " ^
2671 Printexc.to_string exn
);
2675 let config_of c attrs
=
2679 | "scroll-bar-width" -> { c with scrollw
= max
0 (int_of_string v
) }
2680 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string v
) }
2681 | "case-insensitive-search" -> { c with icase
= bool_of_string v
}
2682 | "preload" -> { c with preload = bool_of_string v
}
2683 | "page-bias" -> { c with pagebias
= int_of_string v
}
2684 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string v
) }
2685 | "auto-scroll-step" ->
2686 { c with autoscrollstep = max
0 (int_of_string v
) }
2687 | "max-height-fit" -> { c with maxhfit
= bool_of_string v
}
2688 | "crop-hack" -> { c with crophack
= bool_of_string v
}
2689 | "throttle" -> { c with showall
= bool_of_string v
}
2690 | "highlight-links" -> { c with hlinks
= bool_of_string v
}
2691 | "under-cursor-info" -> { c with underinfo
= bool_of_string v
}
2692 | "vertical-margin" ->
2693 { c with interpagespace = max
0 (int_of_string v
) }
2695 let zoom = float_of_string v
/. 100. in
2696 let zoom = max
0.01 (min
2.2 zoom) in
2697 { c with zoom = zoom }
2698 | "presentation" -> { c with presentation = bool_of_string v
}
2699 | "rotation-angle" -> { c with angle
= int_of_string v
}
2700 | "width" -> { c with winw
= max
20 (int_of_string v
) }
2701 | "height" -> { c with winh
= max
20 (int_of_string v
) }
2702 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string v
}
2703 | "proportional-display" -> { c with proportional
= bool_of_string v
}
2704 | "pixmap-cache-size" -> { c with memlimit
= max
2 (int_of_string v
) }
2705 | "tex-count" -> { c with texcount
= max
1 (int_of_string v
) }
2706 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string v
) }
2707 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string v
) }
2708 | "persistent-location" -> { c with jumpback
= bool_of_string v
}
2711 prerr_endline
("Error processing attribute (`" ^
2712 k ^
"'=`" ^ v ^
"'): " ^
Printexc.to_string exn
);
2715 let rec fold c = function
2718 let c = apply c k v
in
2724 let fromstring f pos
n v
d =
2727 dolog "Error processing attribute (%S=%S) at %d\n%s"
2728 n v pos
(Printexc.to_string exn
)
2733 let bookmark_of attrs
=
2734 let rec fold title page rely
= function
2735 | ("title", v
) :: rest
-> fold v page rely rest
2736 | ("page", v
) :: rest
-> fold title v rely rest
2737 | ("rely", v
) :: rest
-> fold title page v rest
2738 | _
:: rest
-> fold title page rely rest
2739 | [] -> title, page
, rely
2741 fold "invalid" "0" "0" attrs
2745 let rec fold path page rely
pan = function
2746 | ("path", v
) :: rest
-> fold v page rely
pan rest
2747 | ("page", v
) :: rest
-> fold path v rely
pan rest
2748 | ("rely", v
) :: rest
-> fold path page v
pan rest
2749 | ("pan", v
) :: rest
-> fold path page rely v rest
2750 | _
:: rest
-> fold path page rely
pan rest
2751 | [] -> path
, page
, rely
, pan
2753 fold "" "0" "0" "0" attrs
2756 let setconf dst src
=
2757 dst
.scrollw
<- src
.scrollw
;
2758 dst
.scrollh
<- src
.scrollh
;
2759 dst
.icase
<- src
.icase
;
2760 dst
.preload <- src
.preload;
2761 dst
.pagebias
<- src
.pagebias
;
2762 dst
.verbose
<- src
.verbose
;
2763 dst
.scrollstep
<- src
.scrollstep
;
2764 dst
.maxhfit
<- src
.maxhfit
;
2765 dst
.crophack
<- src
.crophack
;
2766 dst
.autoscrollstep <- src
.autoscrollstep;
2767 dst
.showall
<- src
.showall
;
2768 dst
.hlinks
<- src
.hlinks
;
2769 dst
.underinfo
<- src
.underinfo
;
2770 dst
.interpagespace <- src
.interpagespace;
2771 dst
.zoom <- src
.zoom;
2772 dst
.presentation <- src
.presentation;
2773 dst
.angle
<- src
.angle
;
2774 dst
.winw
<- src
.winw
;
2775 dst
.winh
<- src
.winh
;
2776 dst
.savebmarks
<- src
.savebmarks
;
2777 dst
.memlimit
<- src
.memlimit
;
2778 dst
.proportional
<- src
.proportional
;
2779 dst
.texcount
<- src
.texcount
;
2780 dst
.sliceheight
<- src
.sliceheight
;
2781 dst
.thumbw
<- src
.thumbw
;
2782 dst
.jumpback
<- src
.jumpback
;
2786 let l = String.length
s in
2787 let b = Buffer.create
l in
2793 let h = Hashtbl.create
10 in
2794 let dc = { defconf with angle
= defconf.angle
} in
2795 let rec toplevel v t spos epos
=
2797 | Vdata
| Vcdata
| Vend
-> v
2798 | Vopen
("llppconfig", attrs
, closed
) ->
2801 else { v
with f = llppconfig
}
2803 error
"unexpected subelement at top level" s spos
2804 | Vclose tag
-> error
"unexpected close at top level" s spos
2806 and llppconfig v t spos epos
=
2808 | Vdata
| Vcdata
| Vend
-> v
2809 | Vopen
("defaults", attrs
, closed
) ->
2810 let c = config_of dc attrs
in
2814 else { v
with f = skip
"defaults" (fun () -> v
) }
2816 | Vopen
("doc", attrs
, closed
) ->
2817 let pathent, spage
, srely
, span
= doc_of attrs
in
2818 let path = unent pathent
2819 and pageno = fromstring int_of_string spos
"page" spage
0
2820 and rely
= fromstring float_of_string spos
"rely" srely
0.0
2821 and pan = fromstring int_of_string spos
"pan" span
0 in
2822 let c = config_of dc attrs
in
2823 let anchor = (pageno, rely
) in
2825 then (Hashtbl.add
h path (c, [], pan, anchor); v
)
2826 else { v
with f = doc
path pan anchor c [] }
2828 | Vopen
(tag
, _
, closed
) ->
2829 error
"unexpected subelement in llppconfig" s spos
2831 | Vclose
"llppconfig" -> { v
with f = toplevel }
2832 | Vclose tag
-> error
"unexpected close in llppconfig" s spos
2834 and doc
path pan anchor c bookmarks v t spos epos
=
2836 | Vdata
| Vcdata
-> v
2837 | Vend
-> error
"unexpected end of input in doc" s spos
2838 | Vopen
("bookmarks", attrs
, closed
) ->
2839 { v
with f = pbookmarks
path pan anchor c bookmarks }
2841 | Vopen
(tag
, _
, _
) ->
2842 error
"unexpected subelement in doc" s spos
2845 Hashtbl.add
h path (c, List.rev
bookmarks, pan, anchor);
2846 { v
with f = llppconfig
}
2848 | Vclose tag
-> error
"unexpected close in doc" s spos
2850 and pbookmarks
path pan anchor c bookmarks v t spos epos
=
2852 | Vdata
| Vcdata
-> v
2853 | Vend
-> error
"unexpected end of input in bookmarks" s spos
2854 | Vopen
("item", attrs
, closed
) ->
2855 let titleent, spage
, srely
= bookmark_of attrs
in
2856 let page = fromstring int_of_string spos
"page" spage
0
2857 and rely
= fromstring float_of_string spos
"rely" srely
0.0 in
2858 let bookmarks = (unent titleent, 0, page, rely
) :: bookmarks in
2860 then { v
with f = pbookmarks
path pan anchor c bookmarks }
2863 { v
with f = skip
"item" f }
2866 error
"unexpected subelement in bookmarks" s spos
2868 | Vclose
"bookmarks" ->
2869 { v
with f = doc
path pan anchor c bookmarks }
2871 | Vclose tag
-> error
"unexpected close in bookmarks" s spos
2873 and skip tag
f v t spos epos
=
2875 | Vdata
| Vcdata
-> v
2877 error
("unexpected end of input in skipped " ^ tag
) s spos
2878 | Vopen
(tag'
, _
, closed
) ->
2882 let f'
() = { v
with f = skip tag
f } in
2883 { v
with f = skip tag'
f'
}
2887 else error
("unexpected close in skipped " ^ tag
) s spos
2890 parse
{ f = toplevel; accu = () } s;
2896 let len = in_channel_length ic
in
2897 let s = String.create
len in
2898 really_input ic
s 0 len;
2901 | Parse_error
(msg
, s, pos
) ->
2902 let subs = subs s pos
in
2903 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
2904 failwith
("parse error: " ^
s)
2907 failwith
("config load error: " ^
Printexc.to_string exn
)
2913 let dir = Filename.concat
home ".config" in
2914 if Sys.is_directory
dir then dir else home
2917 Filename.concat
dir "llpp.conf"
2921 if Sys.file_exists
path
2924 (try Some
(open_in_bin
path)
2927 ("Error opening configuation file `" ^
path ^
"': " ^
2928 Printexc.to_string exn
);
2937 ("Error loading configuation from `" ^
path ^
"': " ^
2938 Printexc.to_string exn
);
2944 f (Hashtbl.create
0, defconf)
2949 let pc, pb
, px
, pa
=
2951 Hashtbl.find
h (Filename.basename
state.path)
2952 with Not_found
-> dc, [], 0, (0, 0.0)
2956 state.bookmarks <- pb
;
2959 then state.anchor <- pa
2960 else cbput state.hists
.nav pa
;
2965 let add_attrs bb always
dc c =
2968 then Printf.bprintf bb
"\n %s='%b'" s a
2971 then Printf.bprintf bb
"\n %s='%d'" s a
2974 then Printf.bprintf bb
"\n %s='%f'" s (a*.100.)
2978 then dc.winw
, dc.winh
2980 match state.fullscreen
with
2982 | None
-> c.winw
, c.winh
2984 let zoom, presentation, interpagespace, showall
=
2986 then dc.zoom, dc.presentation, dc.interpagespace, dc.showall
2988 match state.mode
with
2989 | Birdseye
(bc
, _
, _
, _
, _
) ->
2990 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.showall
2991 | _
-> c.zoom, c.presentation, c.interpagespace, c.showall
2993 oi
"width" w dc.winw
;
2994 oi
"height" h dc.winh
;
2995 oi
"scroll-bar-width" c.scrollw
dc.scrollw
;
2996 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
2997 ob "case-insensitive-search" c.icase
dc.icase
;
2998 ob "preload" c.preload dc.preload;
2999 oi
"page-bias" c.pagebias
dc.pagebias
;
3000 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
3001 oi
"auto-scroll-step" c.autoscrollstep dc.autoscrollstep;
3002 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
3003 ob "crop-hack" c.crophack
dc.crophack
;
3004 ob "throttle" showall
dc.showall
;
3005 ob "highlight-links" c.hlinks
dc.hlinks
;
3006 ob "under-cursor-info" c.underinfo
dc.underinfo
;
3007 oi
"vertical-margin" interpagespace dc.interpagespace;
3008 oz
"zoom" zoom dc.zoom;
3009 ob "presentation" presentation dc.presentation;
3010 oi
"rotation-angle" c.angle
dc.angle
;
3011 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
3012 ob "proportional-display" c.proportional
dc.proportional
;
3013 oi
"pixmap-cache-size" c.memlimit
dc.memlimit
;
3014 oi
"texcount" c.texcount
dc.texcount
;
3015 oi
"slice-height" c.sliceheight
dc.sliceheight
;
3016 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
3017 ob "persistent-location" c.jumpback
dc.jumpback
;
3021 let bb = Buffer.create
32768 in
3023 Buffer.add_string
bb "<llppconfig>\n<defaults ";
3024 add_attrs bb true dc dc;
3025 Buffer.add_string
bb "/>\n";
3027 let adddoc path pan anchor c bookmarks =
3028 if bookmarks == [] && c = dc && anchor = emptyanchor
3031 Printf.bprintf
bb "<doc path='%s'"
3032 (enent
path 0 (String.length
path));
3034 if anchor <> emptyanchor
3036 let n, y = anchor in
3037 Printf.bprintf
bb " page='%d'" n;
3038 Printf.bprintf
bb " rely='%f'" y;
3042 then Printf.bprintf
bb " pan='%d'" pan;
3044 add_attrs bb false dc c;
3046 begin match bookmarks with
3047 | [] -> Buffer.add_string
bb "/>\n"
3049 Buffer.add_string
bb ">\n<bookmarks>\n";
3050 List.iter
(fun (title, _level
, page, rely
) ->
3052 "<item title='%s' page='%d' rely='%f'/>\n"
3053 (enent
title 0 (String.length
title))
3057 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
3063 match state.mode
with
3064 | Birdseye
(_
, pan, _
, _
, _
) -> pan
3067 let basename = Filename.basename state.path in
3068 adddoc basename pan (getanchor ())
3071 if state.ascrollstep
> 0
3072 then state.ascrollstep
3073 else conf.autoscrollstep }
3074 (if conf.savebmarks
then state.bookmarks else []);
3076 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
3078 then adddoc path x y c bookmarks
3080 Buffer.add_string
bb "</llppconfig>";
3083 if Buffer.length
bb > 0
3086 let tmp = path ^
".tmp" in
3087 let oc = open_out_bin
tmp in
3088 Buffer.output_buffer
oc bb;
3090 Sys.rename
tmp path;
3093 ("error while saving configuration: " ^
Printexc.to_string exn
)
3100 ["-p", Arg.String
(fun s -> state.password
<- s) , " Set password"
3101 ;("-v", Arg.Unit
(fun () -> print_endline
Help.version
; exit
0),
3102 " Print version and exit")]
3104 (fun s -> state.path <- s)
3105 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
3107 if String.length
state.path = 0
3108 then (prerr_endline
"file name missing"; exit
1);
3112 let _ = Glut.init
Sys.argv
in
3113 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
3114 let () = Glut.initWindowSize
conf.winw
conf.winh
in
3115 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
3118 if Sys.os_type
= "Unix"
3120 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
3122 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
3123 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
3124 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
3125 Unix.bind
sock addr;
3127 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
3128 Unix.connect
csock addr;
3129 let ssock, _ = Unix.accept
sock in
3132 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
3133 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
3137 at_exit
(fun () -> Unix.shutdown
ssock Unix.SHUTDOWN_ALL
);
3141 let () = Glut.displayFunc
display in
3142 let () = Glut.reshapeFunc
reshape in
3143 let () = Glut.keyboardFunc
keyboard in
3144 let () = Glut.specialFunc
special in
3145 let () = Glut.idleFunc
(Some
idle) in
3146 let () = Glut.mouseFunc
mouse in
3147 let () = Glut.motionFunc
motion in
3148 let () = Glut.passiveMotionFunc
pmotion in
3150 init
ssock (conf.angle
, conf.proportional
, conf.texcount
, conf.sliceheight
);
3151 state.csock <- csock;
3152 state.ssock <- ssock;
3153 state.text <- "Opening " ^
state.path;
3154 writeopen state.path state.password
;
3158 let rec handlelablglutbug () =
3161 with Glut.BadEnum
"key in special_of_int" ->
3162 showtext '
!'
" LablGlut bug: special key not recognized";
3163 handlelablglutbug ()
3165 handlelablglutbug ();