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
160 type outline
= string * int * int * float;;
162 | Oarray
of outline array
163 | Olist
of outline list
164 | Onarrow
of string * outline array
* outline array
167 type rect
= (float * float * float * float * float * float * float * float);;
169 type pagemapkey
= (pageno
* width
* angle
* proportional
* gen
);;
171 type anchor
= pageno
* top
;;
174 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
175 | Outline
of (bool * int * int * outline array
* string * int)
176 | Textentry
of (textentry
* mode
)
180 let isbirdseye = function Birdseye _
-> true | _
-> false;;
181 let istextentry = function Textentry _
-> true | _
-> false;;
184 { mutable csock
: Unix.file_descr
185 ; mutable ssock
: Unix.file_descr
189 ; mutable anchor
: anchor
191 ; mutable layout
: layout list
192 ; pagemap
: (pagemapkey
, (opaque
* pixmapsize
)) Hashtbl.t
193 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
194 ; mutable pagecount
: int
195 ; pagecache
: string circbuf
196 ; mutable rendering
: bool
197 ; mutable mstate
: mstate
198 ; mutable searchpattern
: string
199 ; mutable rects
: (pageno
* recttype
* rect
) list
200 ; mutable rects1
: (pageno
* recttype
* rect
) list
201 ; mutable text
: string
202 ; mutable fullscreen
: (width
* height
) option
203 ; mutable mode
: mode
204 ; mutable outlines
: outlines
205 ; mutable bookmarks
: outline list
206 ; mutable path
: string
207 ; mutable password
: string
208 ; mutable invalidated
: int
209 ; mutable colorscale
: float
210 ; mutable memused
: int
212 ; mutable throttle
: layout list
option
213 ; mutable ascrollstep
: int
214 ; mutable help
: string list
215 ; mutable docinfo
: (int * string) list
219 { pat
: string circbuf
220 ; pag
: string circbuf
221 ; nav
: anchor circbuf
235 ; autoscrollstep
= 24
241 ; presentation
= false
246 ; proportional
= true
247 ; memlimit
= 32*1024*1024
254 let conf = { defconf with angle
= defconf.angle
};;
265 ; pagemap
= Hashtbl.create
10
266 ; pagecache
= cbnew 100 ""
277 ; outlines
= Olist
[]
283 { nav
= cbnew 100 (0, 0.0)
300 Printf.kprintf prerr_endline fmt
302 Printf.kprintf ignore fmt
306 let len = String.length s
in
308 let b = Buffer.create
n in
309 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
310 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
311 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
312 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
313 Buffer.add_string
b s
;
314 let s'
= Buffer.contents
b in
315 let n'
= Unix.write fd
s'
0 n in
316 if n'
!= n then failwith
"write failed";
321 let n = Unix.read fd
s 0 4 in
322 if n != 4 then failwith
"incomplete read(len)";
324 lor (Char.code
s.[0] lsl 24)
325 lor (Char.code
s.[1] lsl 16)
326 lor (Char.code
s.[2] lsl 8)
327 lor (Char.code
s.[3] lsl 0)
329 let s = String.create
len in
330 let n = Unix.read fd
s 0 len in
331 if n != len then failwith
"incomplete read(data)";
336 let b = Buffer.create
10 in
337 Buffer.add_string
b s;
338 let rec combine = function
341 Buffer.add_char
b ' '
;
344 | `
b b -> if b then "1" else "0"
346 | `i i
-> string_of_int i
347 | `f f
-> string_of_float f
348 | `I f
-> string_of_int
(truncate f
)
350 Buffer.add_string
b s;
357 let cmd = Buffer.contents
(makecmd s l
) in
358 writecmd state.csock
cmd;
364 let d = conf.winh
- h
in
371 let rec f pn ph pi fh l
=
373 | (n, _
, h
, _
) :: rest
->
374 let ips = calcips h
in
379 if isbirdseye state.mode
&& pn
= 0
384 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
389 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
393 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
396 let fh = f 0 0 0 0 state.pdims
in
400 let getpageyh pageno
=
401 let rec f pn ph pi y l
=
403 | (n, _
, h
, _
) :: rest
->
404 let ips = calcips h
in
407 let h = if n = pageno
then h else ph
in
408 if conf.presentation
&& n = pageno
410 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
412 y
+ (pageno
- pn
) * (ph
+ pi
), h
414 let y = y + (if conf.presentation
then pi
else 0) in
415 let y = y + (n - pn
) * (ph
+ pi
) in
419 y + (pageno
- pn
) * (ph
+ pi
), ph
421 f 0 0 0 0 state.pdims
424 let getpagey pageno
= fst
(getpageyh pageno
);;
427 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~cacheleft ~accu
=
428 let ((w
, h, ips, x
) as curr
), rest
, pdimno
, yinc
=
430 | (pageno'
, w
, h, x
) :: rest
when pageno'
= pageno
->
431 let ips = calcips h in
433 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
437 (w
, h, ips, x
), rest
, pdimno
+ 1, yinc
439 prev
, pdims
, pdimno
, 0
441 let dy = dy + yinc in
442 let py = py + yinc in
443 if pageno
= state.pagecount
|| cacheleft
= 0 || dy >= sh
448 if py + h <= vy - yinc
450 let py = py + h + ips in
451 let dy = max
0 (py - y) in
461 let pagey = vy - py in
462 let pagevh = h - pagey in
463 let pagevh = min
(sh
- dy) pagevh in
464 let off = if yinc > 0 then py - vy else 0 in
465 let py = py + h + ips in
471 ; pagedispy
= dy + off
472 ; pagey = pagey + off
473 ; pagevh = pagevh - off
477 let accu = e :: accu in
484 ~cacheleft
:(cacheleft
-1)
487 if state.invalidated
= 0
497 ~cacheleft
:(cbcap state.pagecache
)
507 let y = state.y + incr
in
509 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
513 let getopaque pageno
=
514 try Some
(Hashtbl.find
state.pagemap
515 (pageno
, state.w
, conf.angle
, conf.proportional
, state.gen
))
516 with Not_found
-> None
519 let cache pageno opaque
=
520 Hashtbl.replace
state.pagemap
521 (pageno
, state.w
, conf.angle
, conf.proportional
, state.gen
) opaque
524 let validopaque opaque
= String.length opaque
> 0;;
527 match getopaque l
.pageno
with
528 | None
when not
state.rendering
->
529 state.rendering
<- true;
530 cache l
.pageno
("", -1);
531 wcmd "render" [`i
(l
.pageno
+ 1)
538 let loadlayout layout =
539 let rec f all
= function
541 begin match getopaque l
.pageno
with
542 | None
-> render l
; f false ls
543 | Some
(opaque
, _
) -> f (all
&& validopaque opaque
) ls
547 f (layout <> []) layout;
550 let findpageforopaque opaque
=
552 (fun k
(v
, s) a
-> if v
= opaque
then Some
(k
, s) else a
)
556 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
562 let memleft = conf.memlimit
- state.memused
in
565 let opaque = cbpeek state.pagecache
in
566 match findpageforopaque opaque with
567 | Some
((n, _
, _
, _
, _
), size
) ->
568 memleft + size
>= 0 && not
(pagevisible state.layout n)
575 let presentation = conf.presentation in
576 let interpagespace = conf.interpagespace in
577 let maxy = state.maxy in
578 conf.presentation <- false;
579 conf.interpagespace <- 0;
580 state.maxy <- calcheight ();
582 match state.layout with
584 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
586 let y = if y < conf.winh
then 0 else y - conf.winh
in
587 let pages = layout y (conf.winh
*3) in
588 List.iter
render pages;
589 conf.presentation <- presentation;
590 conf.interpagespace <- interpagespace;
596 let y = min
state.maxy y in
597 let pages = layout y conf.winh
in
598 let ready = loadlayout pages in
604 state.layout <- pages;
605 state.throttle
<- None
;
606 Glut.postRedisplay
();
609 state.throttle
<- Some
pages;
614 state.layout <- pages;
615 state.throttle
<- None
;
616 Glut.postRedisplay
();
618 begin match state.mode
with
619 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
620 if not
(pagevisible pages pageno
)
622 match state.layout with
625 state.mode
<- Birdseye
(conf, leftx
, l
.pageno
, hooverpageno
, anchor
)
632 let gotoy_and_clear_text y =
634 if not
conf.verbose
then state.text
<- "";
637 let emptyanchor = (0, 0.0);;
640 match state.layout with
642 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
645 let getanchory (n, top
) =
646 let y, h = getpageyh n in
647 y + (truncate
(top
*. float h));
650 let gotoanchor anchor
=
651 gotoy (getanchory anchor
);
655 cbput state.hists
.nav
(getanchor ());
659 let anchor = cbgetc state.hists
.nav ~
-1 in
664 let y, h = getpageyh n in
665 gotoy_and_clear_text (y + (truncate
(top
*. float h)));
668 let gotopage1 n top
=
669 let y = getpagey n in
670 gotoy_and_clear_text (y + top
);
678 state.invalidated
<- state.invalidated
+ 1;
682 let c = c *. state.colorscale
in
687 state.maxy <- calcheight ();
688 match state.mode
with
689 | Birdseye
(_
, _
, pageno
, _
, _
) ->
690 let y, h = getpageyh pageno
in
691 let top = (conf.winh
- h) / 2 in
692 gotoy (max
0 (y - top))
693 | _
-> gotoanchor state.anchor
697 GlMat.mode `projection
;
698 GlMat.load_identity
();
699 GlMat.rotate ~x
:1.0 ~angle
:180.0 ();
700 GlMat.translate ~x
:~
-.1.0 ~
y:~
-.1.0 ();
701 GlMat.scale3
(2.0 /. float state.w
, 2.0 /. float conf.winh
, 1.0);
704 GlMat.translate ~x
:(float state.x
) ();
709 GlMat.mode `projection
;
710 GlMat.load_identity
();
711 GlMat.rotate ~x
:1.0 ~angle
:180.0 ();
712 GlMat.translate ~x
:~
-.1.0 ~
y:~
-.1.0 ();
713 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
717 if state.invalidated
= 0
718 then state.anchor <- getanchor ();
721 let w = truncate
(float w *. conf.zoom
) - conf.scrollw
in
725 GlMat.mode `modelview
;
726 GlMat.load_identity
();
727 GlClear.color
(scalecolor 1.0);
728 GlClear.clear
[`color
];
731 wcmd "geometry" [`i
w; `i
h];
735 GlDraw.color
(0.0, 0.0, 0.0);
737 (0.0, float (conf.winh
- 18))
738 (float (conf.winw
- conf.scrollw
- 1), float conf.winh
)
740 let font = Glut.BITMAP_8_BY_13
in
741 GlDraw.color
(1.0, 1.0, 1.0);
742 GlPix.raster_pos ~x
:0.0 ~
y:(float (conf.winh
- 5)) ();
743 Glut.bitmapCharacter ~
font ~
c:(Char.code
c);
744 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c)) s;
748 let len = String.length
state.text
in
749 match state.mode
with
750 | Textentry
((c, text
, _
, _
, _
), _
) ->
754 text ^
" [" ^
state.text ^
"]"
761 if len > 0 then showtext ' '
state.text
765 state.text
<- Printf.sprintf
"%c%s" c s;
766 Glut.postRedisplay
();
775 state.rects
<- state.rects1
;
776 Glut.postRedisplay
()
779 let n = Scanf.sscanf
cmd "C %u" (fun n -> n) in
780 state.pagecount
<- n;
781 state.invalidated
<- state.invalidated
- 1;
782 if state.invalidated
= 0
786 let s = Scanf.sscanf
cmd "t %n"
787 (fun n -> String.sub
cmd n (String.length
cmd - n))
789 Glut.setWindowTitle
s
792 let s = Scanf.sscanf
cmd "T %n"
793 (fun n -> String.sub
cmd n (String.length
cmd - n))
795 if istextentry state.mode
802 Glut.postRedisplay
();
808 let s = Scanf.sscanf
cmd "V %n"
809 (fun n -> String.sub
cmd n (String.length
cmd - n))
815 let pageno, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
816 Scanf.sscanf
cmd "F %u %d %f %f %f %f %f %f %f %f"
817 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
818 (p
, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
820 let y = (getpagey pageno) + truncate y0
in
823 state.rects1
<- [pageno, c, (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
)]
826 let pageno, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
827 Scanf.sscanf
cmd "R %u %d %f %f %f %f %f %f %f %f"
828 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
829 (p
, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
832 (pageno, c, (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) :: state.rects1
835 let n, w, h, r
, l
, s, p
=
836 Scanf.sscanf
cmd "r %u %u %u %u %d %u %s"
837 (fun n w h r l
s p
->
838 (n-1, w, h, r
, l
!= 0, s, p
))
841 Hashtbl.replace
state.pagemap
(n, w, r
, l
, state.gen
) (p
, s);
842 state.memused
<- state.memused
+ s;
845 match state.throttle
with
846 | None
-> state.layout
847 | Some
layout -> layout
851 if (state.memused
<= conf.memlimit
) || cbempty state.pagecache
854 let evictedopaque = cbpeek state.pagecache
in
855 match findpageforopaque evictedopaque with
856 | None
-> failwith
"bug in gc"
857 | Some
((evictedn
, _
, _
, _
, gen
) as k
, evictedsize
) ->
858 if state.gen
!= gen
|| not
(pagevisible layout evictedn
)
860 wcmd "free" [`
s evictedopaque];
861 state.memused
<- state.memused
- evictedsize
;
862 Hashtbl.remove
state.pagemap k
;
863 cbdecr state.pagecache
;
870 cbput state.pagecache p
;
871 state.rendering
<- false;
873 begin match state.throttle
with
875 if pagevisible state.layout n
878 let allvisible = loadlayout state.layout in
879 if allvisible then preload ();
886 let y = getpagey l
.pageno + l
.pagey in
891 let (n, w, h, x
) as pdim
=
892 Scanf.sscanf
cmd "l %u %u %u %u" (fun n w h x
-> n, w, h, x
)
894 state.pdims
<- pdim
:: state.pdims
897 let (l
, n, t
, h, pos
) =
898 Scanf.sscanf
cmd "o %u %u %d %u %n" (fun l
n t
h pos
-> l
, n, t
, h, pos
)
900 let s = String.sub
cmd pos
(String.length
cmd - pos
) in
902 let l = String.length
s in
903 let b = Buffer.create
(String.length
s) in
910 | '
\xa0'
when pc2 -> Buffer.add_char
b ' '
; false
913 let c = if Char.code
c land 0x80 = 0 then c else '?'
in
922 let outline = (s, l, n, float t
/. float h) in
924 match state.outlines with
925 | Olist
outlines -> Olist
(outline :: outlines)
926 | Oarray _
-> Olist
[outline]
927 | Onarrow _
-> Olist
[outline]
929 state.outlines <- outlines
933 let s = Scanf.sscanf
cmd "i %n"
934 (fun n -> String.sub
cmd n (String.length
cmd - n))
936 let len = String.length
s in
937 let rec fold accu pos
=
939 try String.index_from
s pos '
\n'
with Not_found
-> len
944 let line = String.sub
s pos
(eolpos - pos
) in
945 fold ((1, line)::accu) (eolpos+1)
947 state.docinfo
<- fold state.docinfo
0
950 dolog "unknown cmd `%S'" cmd
953 let now = Unix.gettimeofday
;;
957 let r, _
, _
= Unix.select
[state.csock
] [] [] delay
in
960 if state.ascrollstep
> 0
962 let y = state.y + state.ascrollstep
in
963 let y = if y >= state.maxy then 0 else y in
969 let cmd = readcmd state.csock
in
978 let action = function
979 | HCprev
-> cbget cb ~
-1
980 | HCnext
-> cbget cb
1
981 | HCfirst
-> cbget cb ~
-(cb
.rc)
982 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
983 and cancel
() = cb
.rc <- rc
987 let search pattern forward
=
988 if String.length pattern
> 0
991 match state.layout with
994 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
997 let b = makecmd "search"
998 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
1000 Buffer.add_char
b '
,'
;
1001 Buffer.add_string
b pattern
;
1002 Buffer.add_char
b '
\000'
;
1005 writecmd state.csock
cmd;
1008 let intentry text key
=
1009 let c = Char.unsafe_chr key
in
1012 let s = "x" in s.[0] <- c;
1013 let text = text ^
s in
1017 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1022 let b = Buffer.create
(String.length
s + 1) in
1023 Buffer.add_string
b s;
1024 Buffer.add_char
b c;
1028 let textentry text key
=
1029 let c = Char.unsafe_chr key
in
1031 | _
when key
>= 32 && key
< 127 ->
1032 let text = addchar text c in
1036 dolog "unhandled key %d char `%c'" key
(Char.unsafe_chr key
);
1040 let reinit angle proportional
=
1041 conf.angle
<- angle
;
1042 conf.proportional
<- proportional
;
1044 wcmd "reinit" [`i angle
; `
b proportional
];
1048 let zoom = max
0.01 (min
2.2 zoom) in
1049 if zoom <> conf.zoom
1054 reshape conf.winw
conf.winh
;
1055 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
1059 let enterbirdseye () =
1060 let zoom = float conf.thumbw
/. float conf.winw
in
1061 let birdseyepageno =
1062 let rec fold candidate
= function
1064 | l :: _
when l.pagey = 0 -> l.pageno
1065 | l :: rest
-> fold l.pageno rest
1069 state.mode
<- Birdseye
(
1070 { conf with zoom = conf.zoom }, state.x
, birdseyepageno, -1, getanchor ()
1073 conf.presentation <- false;
1074 conf.interpagespace <- 10;
1075 conf.hlinks
<- false;
1077 state.mstate
<- Mnone
;
1078 conf.showall
<- false;
1079 Glut.setCursor
Glut.CURSOR_INHERIT
;
1082 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1087 reshape conf.winw
conf.winh
;
1090 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
1092 conf.zoom <- c.zoom;
1093 conf.presentation <- c.presentation;
1094 conf.interpagespace <- c.interpagespace;
1095 conf.showall
<- c.showall
;
1096 conf.hlinks
<- c.hlinks
;
1100 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1103 reshape conf.winw
conf.winh
;
1104 state.anchor <- if goback
then anchor else (pageno, 0.0);
1107 let togglebirdseye () =
1108 match state.mode
with
1109 | Birdseye vals
-> leavebirdseye vals
true
1110 | View
| Outline _
-> enterbirdseye ()
1114 let optentry text key
=
1115 let btos b = if b then "on" else "off" in
1116 let c = Char.unsafe_chr key
in
1120 try conf.scrollstep
<- int_of_string
s with exc
->
1121 state.text <- Printf.sprintf
"bad integer `%s': %s"
1122 s (Printexc.to_string exc
)
1124 TEswitch
('#'
, "", None
, intentry, ondone)
1129 conf.autoscrollstep
<- int_of_string
s;
1130 if state.ascrollstep
> 0
1131 then state.ascrollstep
<- conf.autoscrollstep
;
1133 state.text <- Printf.sprintf
"bad integer `%s': %s"
1134 s (Printexc.to_string exc
)
1136 TEswitch
('
*'
, "", None
, intentry, ondone)
1141 let zoom = float (int_of_string
s) /. 100.0 in
1144 state.text <- Printf.sprintf
"bad integer `%s': %s"
1145 s (Printexc.to_string exc
)
1147 TEswitch
('
@'
, "", None
, intentry, ondone)
1152 conf.thumbw
<- max
2 (min
1920 (int_of_string
s));
1154 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
1155 begin match state.mode
with
1156 | Textentry
(_
, Birdseye beye
) ->
1157 leavebirdseye beye
false;
1162 state.text <- Printf.sprintf
"bad integer `%s': %s"
1163 s (Printexc.to_string exc
)
1165 TEswitch
('$'
, "", None
, intentry, ondone)
1170 Some
(int_of_string
s)
1172 state.text <- Printf.sprintf
"bad integer `%s': %s"
1173 s (Printexc.to_string exc
);
1176 | Some angle
-> reinit angle
conf.proportional
1179 TEswitch
('^'
, "", None
, intentry, ondone)
1182 conf.icase
<- not
conf.icase
;
1183 TEdone
("case insensitive search " ^
(btos conf.icase
))
1186 conf.preload <- not
conf.preload;
1188 TEdone
("preload " ^
(btos conf.preload))
1191 conf.verbose
<- not
conf.verbose
;
1192 TEdone
("verbose " ^
(btos conf.verbose
))
1195 conf.maxhfit
<- not
conf.maxhfit
;
1196 state.maxy <- state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
1197 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
1200 conf.crophack
<- not
conf.crophack
;
1201 TEdone
("crophack " ^
btos conf.crophack
)
1204 conf.showall
<- not
conf.showall
;
1205 TEdone
("showall " ^
btos conf.showall
)
1208 conf.underinfo
<- not
conf.underinfo
;
1209 TEdone
("underinfo " ^
btos conf.underinfo
)
1212 conf.savebmarks
<- not
conf.savebmarks
;
1213 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
1219 match state.layout with
1224 conf.interpagespace <- int_of_string
s;
1225 state.maxy <- calcheight ();
1226 let y = getpagey pageno in
1229 state.text <- Printf.sprintf
"bad integer `%s': %s"
1230 s (Printexc.to_string exc
)
1232 TEswitch
('
%'
, "", None
, intentry, ondone)
1235 reinit conf.angle
(not
conf.proportional
);
1236 TEdone
("proprortional display " ^
btos conf.proportional
)
1239 state.text <- Printf.sprintf
"bad option %d `%c'" key
c;
1243 let maxoutlinerows () = (conf.winh
- 31) / 16;;
1245 let enterselector allowdel
outlines errmsg msg
=
1246 if Array.length
outlines = 0
1248 showtext ' ' errmsg
;
1252 Glut.setCursor
Glut.CURSOR_INHERIT
;
1254 match state.layout with
1256 | {pageno=pageno} :: rest
-> pageno
1260 if n = Array.length
outlines
1263 let (_
, _
, outlinepageno
, _
) = outlines.(n) in
1264 if outlinepageno
>= pageno then n else loop (n+1)
1268 state.mode
<- Outline
1269 (allowdel
, active, max
0 (active - maxoutlinerows () / 2), outlines, "", 0);
1270 Glut.postRedisplay
();
1274 let enteroutlinemode () =
1276 match state.outlines with
1279 let a = Array.of_list
(List.rev
l) in
1280 state.outlines <- Oarray
a;
1282 | Onarrow
(pat
, a, b) ->
1283 a, "Outline was narrowed to `" ^ pat ^
"' (Ctrl-u to restore)"
1285 enterselector false outlines "Document has no outline" msg
;
1288 let enterbookmarkmode () =
1289 let bookmarks = Array.of_list
state.bookmarks in
1290 enterselector true bookmarks "Document has no bookmarks (yet)" "";
1293 let enterinfomode () =
1294 let btos = function true -> "on" | _
-> "off" in
1295 let pageno, top = getanchor () in
1297 let autoscrollstep =
1298 if state.ascrollstep
> 0
1299 then state.ascrollstep
1300 else conf.autoscrollstep
1302 (0, "Current parameters")
1303 :: (1, "version " ^
Help.version
)
1304 :: (1, "presentation mode " ^
btos conf.presentation)
1305 :: (1, "case insensitive search " ^
btos conf.icase
)
1306 :: (1, "preload " ^
btos conf.preload)
1307 :: (1, "page bias " ^ string_of_int
conf.pagebias
)
1308 :: (1, "verbose " ^
btos conf.verbose
)
1309 :: (1, "scroll step " ^ string_of_int
conf.scrollstep
)
1310 :: (1, "max fit " ^
btos conf.maxhfit
)
1311 :: (1, "crop hack " ^
btos conf.crophack
)
1312 :: (1, "autoscroll step " ^ string_of_int
autoscrollstep)
1313 :: (1, "throttle " ^
btos conf.showall
)
1314 :: (1, "highlight links " ^
btos conf.hlinks
)
1315 :: (1, "under info " ^
btos conf.underinfo
)
1316 :: (1, "veritcal margin " ^ string_of_int
conf.interpagespace)
1317 :: (1, "zoom " ^
Printf.sprintf
"%-5.1f" (conf.zoom*.100.))
1318 :: (1, "rotation " ^ string_of_int
conf.angle
)
1319 :: (1, "persistent bookmarks " ^
btos conf.savebmarks
)
1320 :: (1, "proportional display " ^
btos conf.proportional
)
1321 :: (1, "pixmap cache size " ^ string_of_int
conf.memlimit
)
1322 :: (1, "pixmap cache used " ^ string_of_int
state.memused
)
1323 :: (1, "thumbnail width " ^ string_of_int
conf.thumbw
)
1324 :: (1, Printf.sprintf
"window dimensions %dx%d " conf.winw
conf.winh
)
1325 :: (0, "Document information")
1326 :: (1, string_of_int
state.pagecount ^
" pages")
1330 let o = Array.create
(List.length
info) ("", 0, pageno, top) in
1331 let rec iteri i
= function
1334 o.(i
) <- (s, l, pageno, top);
1340 enterselector false o "Info not available" "";
1343 let enterhelpmode () =
1344 let pageno, top = getanchor () in
1346 let help = ("Keys for llpp " ^
Help.version
) ::state.help in
1347 let o = Array.create
(List.length
help) ("", 0, pageno, top) in
1348 let rec iteri i
= function
1351 o.(i
) <- (s, (if i
= 0 then 0 else 1), pageno, top);
1357 enterselector false o "Help not available" "";
1360 let quickbookmark ?title
() =
1361 match state.layout with
1367 let sec = Unix.gettimeofday
() in
1368 let tm = Unix.localtime
sec in
1369 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
1373 (tm.Unix.tm_year
+ 1900)
1376 | Some
title -> title
1379 (title, 0, l.pageno, float l.pagey /. float l.pageh
) :: state.bookmarks
1383 state.fullscreen
<- None
;
1384 Glut.reshapeWindow
w h;
1387 let writeopen path password
=
1388 writecmd state.csock
("open " ^ path ^
"\000" ^
state.password ^
"\000");
1389 writecmd state.csock
"info";
1392 let opendoc path password
=
1395 state.password
<- password
;
1396 state.gen
<- state.gen
+ 1;
1398 writeopen path password
;
1399 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1400 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1403 let viewkeyboard ~key ~x ~
y =
1405 state.mode
<- Textentry
(te
, state.mode
);
1408 Glut.postRedisplay
()
1410 let c = Char.chr key
in
1416 let y = getnav () in
1417 gotoy_and_clear_text y
1425 Glut.postRedisplay
()
1428 let ondone isforw
s =
1429 cbput state.hists
.pat
s;
1430 state.searchpattern
<- s;
1433 enttext (c, "", Some
(onhist state.hists
.pat
),
1434 textentry, ondone (c ='
/'
))
1436 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
1437 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
1438 setzoom (min
2.2 (conf.zoom +. incr))
1443 try int_of_string
s with exc
->
1444 state.text <- Printf.sprintf
"bad integer `%s': %s"
1445 s (Printexc.to_string exc
);
1451 state.text <- "page bias is now " ^ string_of_int
n;
1454 enttext ('
+'
, "", None
, intentry, ondone)
1456 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
1457 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
1458 setzoom (max
0.01 (conf.zoom -. decr))
1464 enttext ('
-'
, "", None
, optentry, ondone)
1466 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1469 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1470 let zoom = zoomforh
conf.winw
conf.winh
conf.scrollw
in
1474 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1480 try int_of_string
s with exc
->
1481 state.text <- Printf.sprintf
"bad integer `%s': %s"
1482 s (Printexc.to_string exc
);
1488 cbput state.hists
.pag
(string_of_int
n);
1489 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
1492 let pageentry text key
=
1493 match Char.unsafe_chr key
with
1494 | 'g'
-> TEdone
text
1495 | _
-> intentry text key
1497 let text = "x" in text.[0] <- c;
1498 enttext ('
:'
, text, Some
(onhist state.hists
.pag
), pageentry, ondone)
1501 conf.scrollw
<- if conf.scrollw
> 0 then 0 else defconf.scrollw
;
1502 reshape conf.winw
conf.winh
;
1505 conf.hlinks
<- not
conf.hlinks
;
1506 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
1507 Glut.postRedisplay
()
1510 if state.ascrollstep
= 0
1511 then state.ascrollstep
<- conf.autoscrollstep
1513 conf.autoscrollstep <- state.ascrollstep
;
1514 state.ascrollstep
<- 0;
1518 conf.presentation <- not
conf.presentation;
1519 showtext ' '
("presentation mode " ^
1520 if conf.presentation then "on" else "off");
1521 state.anchor <- getanchor ();
1525 begin match state.fullscreen
with
1527 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
1530 state.fullscreen
<- None
;
1535 gotoy_and_clear_text 0
1538 search state.searchpattern
true
1541 search state.searchpattern
false
1544 begin match state.layout with
1547 gotoy_and_clear_text (getpagey l.pageno)
1551 begin match List.rev
state.layout with
1554 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
1555 gotoy_and_clear_text (getpagey pageno)
1559 begin match state.layout with
1562 let pageno = max
0 (l.pageno-1) in
1563 gotoy_and_clear_text (getpagey pageno)
1568 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
1570 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
1572 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
1576 else (100. *. (float state.y /. float maxy)) in
1579 Printf.sprintf
"Page %d of %d %.2f%%"
1580 (fn+1) state.pagecount
percent
1583 "Pages %d-%d of %d %.2f%%"
1584 (fn+1) (ln
+1) state.pagecount
percent
1589 begin match state.layout with
1592 doreshape (l.pagew
+ conf.scrollw
) l.pageh
;
1593 Glut.postRedisplay
();
1597 enterbookmarkmode ()
1607 match state.layout with
1610 (s, 0, l.pageno, float l.pagey /. float l.pageh
)
1614 enttext ('~'
, "", None
, textentry, ondone)
1618 showtext ' '
"Quick bookmark added";
1621 begin match state.layout with
1623 let rect = getpdimrect
l.pagedimno
in
1627 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
1628 truncate
(1.2 *. (rect.(3) -. rect.(0))))
1630 (truncate
(rect.(1) -. rect.(0)),
1631 truncate
(rect.(3) -. rect.(0)))
1635 doreshape (w + conf.scrollw
) (h + conf.interpagespace)
1637 Glut.postRedisplay
();
1643 reinit (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
1648 (min
(state.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 1.0);
1649 Glut.postRedisplay
()
1651 | 'k'
-> gotoy (clamp (-conf.scrollstep
))
1652 | 'j'
-> gotoy (clamp conf.scrollstep
)
1654 | '
r'
-> opendoc state.path
state.password
1657 vlog "huh? %d %c" key
(Char.chr key
);
1660 let textentrykeyboard ~key ~x ~
y ((c, text, opthist
, onkey
, ondone), mode
) =
1662 state.mode
<- Textentry
(te
, mode
);
1665 Glut.postRedisplay
()
1667 match Char.unsafe_chr key
with
1669 let len = String.length
text in
1673 Glut.postRedisplay
();
1676 let s = String.sub
text 0 (len - 1) in
1677 enttext (c, s, opthist
, onkey
, ondone)
1683 Glut.postRedisplay
()
1686 begin match opthist
with
1688 | Some
(_
, onhistcancel
) -> onhistcancel
()
1691 Glut.postRedisplay
()
1694 begin match onkey
text key
with
1698 Glut.postRedisplay
()
1701 enttext (c, text, opthist
, onkey
, ondone);
1705 Glut.postRedisplay
()
1708 state.mode
<- Textentry
(te
, mode
);
1709 Glut.postRedisplay
()
1713 let birdseyekeyboard ~key ~x ~
y ((_
, _
, pageno, _
, anchor) as beye
) =
1716 leavebirdseye beye
true
1719 let y, h = getpageyh pageno in
1720 let top = (conf.winh
- h) / 2 in
1721 gotoy (max
0 (y - top))
1724 leavebirdseye beye
false
1727 viewkeyboard ~key ~x ~
y
1730 let outlinekeyboard ~key ~x ~
y
1731 (allowdel
, active, first
, outlines, qsearch
, pan
) =
1732 let narrow outlines pattern
=
1733 let reopt = try Some
(Str.regexp_case_fold pattern
) with _
-> None
in
1737 let rec fold accu n =
1741 let (s, _
, _
, _
) as o = outlines.(n) in
1743 if (try ignore
(Str.search_forward re
s 0); true
1744 with Not_found
-> false)
1750 let matched = fold [] (Array.length
outlines - 1) in
1751 if matched = [] then None
else Some
(Array.of_list
matched)
1753 let search active pattern
incr =
1756 if n = Array.length
outlines || n = -1
1759 let (s, _
, _
, _
) = outlines.(n) in
1761 (try ignore
(Str.search_forward re
s 0); true
1762 with Not_found
-> false)
1764 else loop (n + incr)
1769 let re = Str.regexp_case_fold pattern
in
1775 let firstof active = max
0 (active - maxoutlinerows () / 2) in
1778 if String.length qsearch
= 0
1782 Glut.postRedisplay
();
1786 state.mode
<- Outline
(allowdel
, active, first
, outlines, "", pan
);
1787 Glut.postRedisplay
();
1791 let incr = if key
= 18 then -1 else 1 in
1793 match search (active + incr) qsearch
incr with
1795 state.text <- qsearch ^
" [not found]";
1798 state.text <- qsearch
;
1799 active, firstof active
1801 state.mode
<- Outline
(allowdel
, active, first
, outlines, qsearch
, pan
);
1802 Glut.postRedisplay
();
1805 let len = String.length qsearch
in
1812 state.mode
<- Outline
(allowdel
, active, first
, outlines, "", pan
);
1815 let qsearch = String.sub
qsearch 0 (len - 1) in
1817 match search active qsearch ~
-1 with
1819 state.text <- qsearch ^
" [not found]";
1822 state.text <- qsearch;
1823 active, firstof active
1825 state.mode
<- Outline
(allowdel
, active, first
, outlines, qsearch, pan
);
1827 Glut.postRedisplay
()
1830 if active < Array.length
outlines
1832 let (_
, _
, n, t
) = outlines.(active) in
1837 if allowdel
then state.bookmarks <- Array.to_list
outlines;
1839 Glut.postRedisplay
();
1841 | _
when key
>= 32 && key
< 127 ->
1842 let pattern = addchar qsearch (Char.chr key
) in
1844 match search active pattern 1 with
1846 state.text <- pattern ^
" [not found]";
1849 state.text <- pattern;
1850 active, firstof active
1852 state.mode
<- Outline
(allowdel
, active, first
, outlines, pattern, pan
);
1853 Glut.postRedisplay
()
1855 | 14 when not allowdel
-> (* ctrl-n *)
1856 if String.length
qsearch > 0
1858 let optoutlines = narrow outlines qsearch in
1859 begin match optoutlines with
1860 | None
-> state.text <- "can't narrow"
1862 state.mode
<- Outline
(allowdel
, 0, 0, outlines, qsearch, pan
);
1863 match state.outlines with
1866 state.outlines <- Onarrow
(qsearch, outlines, a)
1867 | Onarrow
(pat
, a, b) ->
1868 state.outlines <- Onarrow
(qsearch, outlines, b)
1871 Glut.postRedisplay
()
1873 | 21 when not allowdel
-> (* ctrl-u *)
1875 match state.outlines with
1878 let a = Array.of_list
(List.rev
l) in
1879 state.outlines <- Oarray
a;
1881 | Onarrow
(pat
, a, b) ->
1882 state.outlines <- Oarray
b;
1886 state.mode
<- Outline
(allowdel
, 0, 0, outline, qsearch, pan
);
1887 Glut.postRedisplay
()
1890 state.mode
<- Outline
1891 (allowdel
, active, firstof active, outlines, qsearch, pan
);
1892 Glut.postRedisplay
()
1894 | 127 when allowdel
->
1895 let len = Array.length
outlines - 1 in
1899 state.bookmarks <- [];
1902 let bookmarks = Array.init
len
1904 let i = if i >= active then i + 1 else i in
1917 Glut.postRedisplay
()
1919 | _
-> dolog "unknown key %d" key
1922 let keyboard ~key ~x ~
y =
1927 match state.mode
with
1928 | Outline
outline -> outlinekeyboard ~key ~x ~
y outline
1929 | Textentry
textentry -> textentrykeyboard ~key ~x ~
y textentry
1930 | Birdseye birdseye
-> birdseyekeyboard ~key ~x ~
y birdseye
1931 | View
-> viewkeyboard ~key ~x ~
y
1934 let birdseyespecial key x
y (conf, leftx
, pageno, hooverpageno
, anchor) =
1937 let pageno = max
0 (pageno - 1) in
1938 let rec loop = function
1939 | [] -> gotopage1 pageno 0
1940 | l :: _
when l.pageno = pageno ->
1941 if l.pagedispy
>= 0 && l.pagey = 0
1942 then Glut.postRedisplay
()
1943 else gotopage1 pageno 0
1944 | _
:: rest
-> loop rest
1947 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
1950 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
1951 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
1952 let rec loop = function
1954 let y, h = getpageyh pageno in
1955 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
1957 | l :: rest
when l.pageno = pageno ->
1958 if l.pagevh != l.pageh
1959 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
1960 else Glut.postRedisplay
()
1961 | l :: rest
-> loop rest
1965 | Glut.KEY_PAGE_UP
->
1966 begin match state.layout with
1970 state.mode
<- Birdseye
(
1971 conf, leftx
, l.pageno, hooverpageno
, anchor
1973 gotopage1 l.pageno 0;
1976 let layout = layout (state.y-conf.winh
) conf.winh
in
1978 | [] -> gotoy (clamp (-conf.winh
))
1980 state.mode
<- Birdseye
(
1981 conf, leftx
, l.pageno, hooverpageno
, anchor
1983 gotopage1 l.pageno 0
1986 | [] -> gotoy (clamp (-conf.winh
))
1989 | Glut.KEY_PAGE_DOWN
->
1990 begin match List.rev
state.layout with
1992 let layout = layout (state.y + conf.winh
) conf.winh
in
1993 begin match layout with
1995 let incr = l.pageh
- l.pagevh in
2000 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
2002 Glut.postRedisplay
();
2004 else gotoy (clamp (incr + conf.interpagespace*2));
2008 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
2009 gotopage1 l.pageno 0;
2012 | [] -> gotoy (clamp conf.winh
)
2016 state.mode
<- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
2020 let pageno = state.pagecount
- 1 in
2021 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2022 if not
(pagevisible state.layout pageno)
2025 match List.rev
state.pdims
with
2027 | (_
, _
, h, _
) :: _
-> h
2029 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
2030 else Glut.postRedisplay
();
2034 let setautoscrollspeed goingdown
=
2035 let incr = max
1 (state.ascrollstep
/ 2) in
2036 let astep = max
1 (state.ascrollstep
+ (if goingdown
then incr else -incr)) in
2037 state.ascrollstep
<- astep;
2040 let special ~key ~x ~
y =
2041 match state.mode
with
2042 | View
| (Birdseye _
) when key
= Glut.KEY_F9
->
2046 birdseyespecial key x
y vals
2048 | View
when key
= Glut.KEY_F1
->
2052 if state.ascrollstep
> 0 && (key
= Glut.KEY_DOWN
|| key
= Glut.KEY_UP
)
2053 then setautoscrollspeed (key
= Glut.KEY_DOWN
)
2057 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
2058 | Glut.KEY_UP
-> clamp (-conf.scrollstep
)
2059 | Glut.KEY_DOWN
-> clamp conf.scrollstep
2060 | Glut.KEY_PAGE_UP
->
2061 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2063 match state.layout with
2065 | l :: _
-> state.y - l.pagey
2068 | Glut.KEY_PAGE_DOWN
->
2069 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2071 match List.rev
state.layout with
2073 | l :: _
-> getpagey l.pageno
2076 | Glut.KEY_HOME
-> addnav (); 0
2079 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
2081 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
2082 state.x
<- state.x
- 10;
2084 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
2085 state.x
<- state.x
+ 10;
2090 gotoy_and_clear_text y
2093 ((c, s, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2096 | Glut.KEY_UP
-> action HCprev
2097 | Glut.KEY_DOWN
-> action HCnext
2098 | Glut.KEY_HOME
-> action HCfirst
2099 | Glut.KEY_END
-> action HClast
2102 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2103 Glut.postRedisplay
()
2107 | Outline
(allowdel
, active, first
, outlines, qsearch, pan
) ->
2108 let maxrows = maxoutlinerows () in
2109 let calcfirst first
active =
2112 let rows = active - first
in
2113 if rows > maxrows then active - maxrows else first
2117 let active = active + incr in
2118 let active = max
0 (min
active (Array.length
outlines - 1)) in
2119 let first = calcfirst first active in
2120 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch, pan
);
2121 Glut.postRedisplay
()
2123 let updownlevel incr =
2124 let len = Array.length
outlines in
2125 let (_
, curlevel
, _
, _
) = outlines.(active) in
2127 if i = len then i-1 else if i = -1 then 0 else
2128 let (_
, l, _
, _
) = outlines.(i) in
2129 if l != curlevel
then i else flow (i+incr)
2131 let active = flow active in
2132 let first = calcfirst first active in
2133 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch, pan
);
2134 Glut.postRedisplay
()
2137 | Glut.KEY_UP
-> navigate ~
-1
2138 | Glut.KEY_DOWN
-> navigate 1
2139 | Glut.KEY_PAGE_UP
-> navigate ~
-maxrows
2140 | Glut.KEY_PAGE_DOWN
-> navigate maxrows
2143 if Glut.active_ctrl
!= 0
2145 state.mode
<- Outline
(
2146 allowdel
, active, first, outlines, qsearch, min
0 (pan
+ 1)
2148 Glut.postRedisplay
();
2156 if Glut.active_ctrl
!= 0
2158 state.mode
<- Outline
(
2159 allowdel
, active, first, outlines, qsearch, pan
- 1
2161 Glut.postRedisplay
();
2165 then updownlevel ~
-1
2169 state.mode
<- Outline
(allowdel
, 0, 0, outlines, qsearch, pan
);
2170 Glut.postRedisplay
()
2173 let active = Array.length
outlines - 1 in
2174 let first = max
0 (active - maxrows) in
2175 state.mode
<- Outline
(
2176 allowdel
, active, first, outlines, qsearch, pan
2178 Glut.postRedisplay
()
2183 let drawplaceholder l =
2184 let margin = state.x
+ (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2186 (float l.pagex
, float l.pagedispy
)
2187 (float (l.pagew
+ l.pagex
), float (l.pagedispy
+ l.pagevh))
2189 let x = float (if margin < 0 then -margin else l.pagex
)
2190 and y = float (l.pagedispy
+ 13) in
2191 let font = Glut.BITMAP_8_BY_13
in
2192 GlDraw.color
(0.0, 0.0, 0.0);
2193 GlPix.raster_pos ~
x ~
y ();
2194 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c))
2195 ("Loading " ^ string_of_int
(l.pageno + 1));
2198 let now () = Unix.gettimeofday
();;
2202 match state.mode
with
2203 | Textentry _
-> scalecolor 0.4
2204 | View
| Outline _
-> scalecolor 1.0
2205 | Birdseye
(_
, _
, pageno, hooverpageno
, _
) ->
2206 if l.pageno = hooverpageno
2209 if l.pageno = pageno
2215 begin match getopaque l.pageno with
2216 | Some
(opaque, _
) when validopaque opaque ->
2218 draw
(l.pagedispy
, l.pagew
, l.pagevh, l.pagey, conf.hlinks
)
2222 vlog "draw %d %f sec" l.pageno d;
2230 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
2231 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2232 let sh = float conf.winh
/. sh in
2233 let sh = max
sh (float conf.scrollh
) in
2236 if state.y = state.maxy
2238 else float y /. float maxy
2240 let position = (float conf.winh
-. sh) *. percent in
2243 if position +. sh > float conf.winh
2244 then float conf.winh
-. sh
2250 let scrollindicator () =
2251 GlDraw.color (0.64 , 0.64, 0.64);
2253 (float (conf.winw
- conf.scrollw
), 0.)
2254 (float conf.winw
, float conf.winh
)
2256 GlDraw.color (0.0, 0.0, 0.0);
2258 let position, sh = scrollph state.y in
2260 (float (conf.winw
- conf.scrollw
), position)
2261 (float conf.winw
, position +. sh)
2265 let showsel margin =
2266 match state.mstate
with
2267 | Mnone
| Mscroll _
| Mpan _
| Mzoom _
->
2270 | Msel
((x0
, y0
), (x1
, y1
)) ->
2271 let rec loop = function
2273 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
2274 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
2276 match getopaque l.pageno with
2277 | Some
(opaque, _
) when validopaque opaque ->
2278 let oy = -l.pagey + l.pagedispy
in
2280 (x0
- margin - state.x, y0
,
2281 x1
- margin - state.x, y1
) oy;
2291 let panx = float state.x in
2293 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
2294 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2296 (fun (pageno, c, (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
2298 if l.pageno = pageno
2300 let d = float (l.pagedispy
- l.pagey) in
2301 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
2302 GlDraw.begins `quads
;
2304 GlDraw.vertex2
(x0
+.panx, y0
+.d);
2305 GlDraw.vertex2
(x1
+.panx, y1
+.d);
2306 GlDraw.vertex2
(x2
+.panx, y2
+.d);
2307 GlDraw.vertex2
(x3
+.panx, y3
+.d);
2317 let showoutline () =
2318 match state.mode
with
2319 | Outline
(allowdel
, active, first, outlines, qsearch, pan
) ->
2321 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2322 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2323 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2326 GlDraw.color (1., 1., 1.);
2327 let font = Glut.BITMAP_9_BY_15
in
2328 let draw_string x y s =
2329 GlPix.raster_pos ~
x ~
y ();
2330 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c)) s
2333 if row
= Array.length
outlines || (row
- first) * 16 > conf.winh
2336 let (s, l, _
, _
) = outlines.(row
) in
2337 let y = (row
- first) * 16 in
2342 GlDraw.polygon_mode `both `
line;
2343 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2344 GlDraw.color (1., 1., 1.) ~alpha
:0.9;
2345 GlDraw.rect (0., float (y + 1))
2346 (float (conf.winw
- 1), float (y + 18));
2347 GlDraw.polygon_mode `both `fill
;
2349 GlDraw.color (1., 1., 1.);
2352 let l = String.length
s in
2355 let pan = pan * 2 in
2356 let left = l + pan in
2359 let s = String.sub
s (-pan) left in
2360 draw_string (float x) (float (y + 16)) s
2363 draw_string (float (x + pan*15)) (float (y + 16)) s
2375 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2376 GlDraw.viewport
margin 0 state.w conf.winh
;
2378 GlClear.color (scalecolor 0.5);
2379 GlClear.clear
[`
color];
2382 Gl.enable `scissor_test
;
2383 GlMisc.scissor
0 0 (conf.winw
- conf.scrollw
) conf.winh
;
2385 List.iter
drawpage state.layout;
2388 Gl.disable `scissor_test
2392 let x = -.float state.x in
2393 GlMat.translate ~
x ();
2397 GlDraw.viewport
0 0 conf.winw
conf.winh
;
2402 Glut.swapBuffers
();
2406 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2407 let x = x - margin - state.x in
2408 let rec f = function
2410 begin match getopaque l.pageno with
2411 | Some
(opaque, _
) when validopaque opaque ->
2412 let y = y - l.pagedispy
in
2415 let y = l.pagey + y in
2416 let x = x - l.pagex
in
2417 match whatsunder
opaque x y with
2430 let viewmouse button bstate
x y =
2432 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2433 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2435 match state.mstate
with
2436 | Mzoom
(oldn
, i) ->
2444 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
2446 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
2448 let zoom = conf.zoom +. incr in
2450 state.mstate
<- Mzoom
(n, 0);
2452 state.mstate
<- Mzoom
(n, i+1);
2454 else state.mstate
<- Mzoom
(n, 0)
2456 | _
-> state.mstate
<- Mzoom
(n, 0)
2459 if state.ascrollstep
> 0
2461 setautoscrollspeed (n=4)
2465 then -conf.scrollstep
2466 else conf.scrollstep
2468 let incr = incr * 2 in
2469 let y = clamp incr in
2470 gotoy_and_clear_text y
2473 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
2474 if bstate
= Glut.DOWN
2476 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
2477 state.mstate
<- Mpan
(x, y)
2480 state.mstate
<- Mnone
2482 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollw
->
2483 if bstate
= Glut.DOWN
2485 let position, sh = scrollph state.y in
2486 if y > truncate
position && y < truncate
(position +. sh)
2488 state.mstate
<- Mscroll
2490 let percent = float y /. float conf.winh
in
2491 let desty = truncate
(float (state.maxy - conf.winh
) *. percent) in
2493 state.mstate
<- Mscroll
2495 state.mstate
<- Mnone
2497 | Glut.LEFT_BUTTON
->
2498 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
2499 begin match dest with
2500 | Ulinkgoto
(pageno, top) ->
2504 gotopage1 pageno top;
2510 | Unone
when bstate
= Glut.DOWN
->
2511 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
2512 state.mstate
<- Mpan
(x, y);
2514 | Unone
| Utext _
->
2515 if bstate
= Glut.DOWN
2517 if conf.angle
mod 360 = 0
2519 state.mstate
<- Msel
((x, y), (x, y));
2520 Glut.postRedisplay
()
2524 match state.mstate
with
2527 | Mzoom _
| Mscroll
->
2528 state.mstate
<- Mnone
2531 Glut.setCursor
Glut.CURSOR_INHERIT
;
2532 state.mstate
<- Mnone
2534 | Msel
((x0
, y0
), (x1
, y1
)) ->
2536 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
2537 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
2539 match getopaque l.pageno with
2540 | Some
(opaque, _
) when validopaque opaque ->
2544 List.iter
f state.layout;
2545 copysel
""; (* ugly *)
2546 Glut.setCursor
Glut.CURSOR_INHERIT
;
2547 state.mstate
<- Mnone
;
2554 let birdseyemouse button bstate
x y
2555 (conf, leftx
, pageno, hooverpageno
, anchor) =
2557 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2558 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2559 let rec loop = function
2562 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
2563 && x > margin && x < margin + l.pagew
2565 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
2570 | Glut.OTHER_BUTTON _
-> viewmouse button bstate
x y
2574 let mouse bstate button
x y =
2575 match state.mode
with
2576 | View
-> viewmouse button bstate
x y
2577 | Birdseye beye
-> birdseyemouse button bstate
x y beye
2582 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
2585 match state.mode
with
2588 match state.mstate
with
2589 | Mzoom _
| Mnone
-> ()
2594 state.mstate
<- Mpan
(x, y);
2595 if conf.zoom > 1.0 then state.x <- state.x + dx;
2597 gotoy_and_clear_text y
2600 state.mstate
<- Msel
(a, (x, y));
2601 Glut.postRedisplay
()
2604 let y = min
conf.winh
(max
0 y) in
2605 let percent = float y /. float conf.winh
in
2606 let y = truncate
(float (state.maxy - conf.winh
) *. percent) in
2607 gotoy_and_clear_text y
2611 match state.mode
with
2612 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
2613 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2614 let rec loop = function
2616 if hooverpageno
!= -1
2618 state.mode
<- Birdseye
(conf, leftx
, pageno, -1, anchor);
2619 Glut.postRedisplay
();
2622 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
2623 && x > margin && x < margin + l.pagew
2625 state.mode
<- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
2626 Glut.postRedisplay
();
2634 match state.mstate
with
2636 begin match getunder x y with
2637 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
2639 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
2640 Glut.setCursor
Glut.CURSOR_INFO
2641 | Ulinkgoto
(page
, y) ->
2643 then showtext 'p'
("age: " ^ string_of_int page
);
2644 Glut.setCursor
Glut.CURSOR_INFO
2646 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
2647 Glut.setCursor
Glut.CURSOR_TEXT
2650 | Mpan _
| Msel _
| Mzoom _
| Mscroll
->
2661 match Sys.os_type
with
2662 | "Win32" -> Sys.getenv
"HOMEPATH"
2663 | _
-> Sys.getenv
"HOME"
2666 ("Can not determine home directory location: " ^
2667 Printexc.to_string exn
);
2671 let config_of c attrs
=
2675 | "scroll-bar-width" -> { c with scrollw
= max
0 (int_of_string v
) }
2676 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string v
) }
2677 | "case-insensitive-search" -> { c with icase
= bool_of_string v
}
2678 | "preload" -> { c with preload = bool_of_string v
}
2679 | "page-bias" -> { c with pagebias
= int_of_string v
}
2680 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string v
) }
2681 | "auto-scroll-step" ->
2682 { c with autoscrollstep = max
0 (int_of_string v
) }
2683 | "max-height-fit" -> { c with maxhfit
= bool_of_string v
}
2684 | "crop-hack" -> { c with crophack
= bool_of_string v
}
2685 | "throttle" -> { c with showall
= bool_of_string v
}
2686 | "highlight-links" -> { c with hlinks
= bool_of_string v
}
2687 | "under-cursor-info" -> { c with underinfo
= bool_of_string v
}
2688 | "vertical-margin" ->
2689 { c with interpagespace = max
0 (int_of_string v
) }
2691 let zoom = float_of_string v
/. 100. in
2692 let zoom = max
0.01 (min
2.2 zoom) in
2693 { c with zoom = zoom }
2694 | "presentation" -> { c with presentation = bool_of_string v
}
2695 | "rotation-angle" -> { c with angle
= int_of_string v
}
2696 | "width" -> { c with winw
= max
20 (int_of_string v
) }
2697 | "height" -> { c with winh
= max
20 (int_of_string v
) }
2698 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string v
}
2699 | "proportional-display" -> { c with proportional
= bool_of_string v
}
2700 | "pixmap-cache-size" -> { c with memlimit
= max
2 (int_of_string v
) }
2701 | "tex-count" -> { c with texcount
= max
1 (int_of_string v
) }
2702 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string v
) }
2703 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string v
) }
2706 prerr_endline
("Error processing attribute (`" ^
2707 k ^
"'=`" ^ v ^
"'): " ^
Printexc.to_string exn
);
2710 let rec fold c = function
2713 let c = apply c k v
in
2719 let fromstring f pos
n v
d =
2722 dolog "Error processing attribute (%S=%S) at %d\n%s"
2723 n v pos
(Printexc.to_string exn
)
2728 let bookmark_of attrs
=
2729 let rec fold title page rely
= function
2730 | ("title", v
) :: rest
-> fold v page rely rest
2731 | ("page", v
) :: rest
-> fold title v rely rest
2732 | ("rely", v
) :: rest
-> fold title page v rest
2733 | _
:: rest
-> fold title page rely rest
2734 | [] -> title, page
, rely
2736 fold "invalid" "0" "0" attrs
2740 let rec fold path page rely
pan = function
2741 | ("path", v
) :: rest
-> fold v page rely
pan rest
2742 | ("page", v
) :: rest
-> fold path v rely
pan rest
2743 | ("rely", v
) :: rest
-> fold path page v
pan rest
2744 | ("pan", v
) :: rest
-> fold path page rely v rest
2745 | _
:: rest
-> fold path page rely
pan rest
2746 | [] -> path
, page
, rely
, pan
2748 fold "" "0" "0" "0" attrs
2751 let setconf dst src
=
2752 dst
.scrollw
<- src
.scrollw
;
2753 dst
.scrollh
<- src
.scrollh
;
2754 dst
.icase
<- src
.icase
;
2755 dst
.preload <- src
.preload;
2756 dst
.pagebias
<- src
.pagebias
;
2757 dst
.verbose
<- src
.verbose
;
2758 dst
.scrollstep
<- src
.scrollstep
;
2759 dst
.maxhfit
<- src
.maxhfit
;
2760 dst
.crophack
<- src
.crophack
;
2761 dst
.autoscrollstep <- src
.autoscrollstep;
2762 dst
.showall
<- src
.showall
;
2763 dst
.hlinks
<- src
.hlinks
;
2764 dst
.underinfo
<- src
.underinfo
;
2765 dst
.interpagespace <- src
.interpagespace;
2766 dst
.zoom <- src
.zoom;
2767 dst
.presentation <- src
.presentation;
2768 dst
.angle
<- src
.angle
;
2769 dst
.winw
<- src
.winw
;
2770 dst
.winh
<- src
.winh
;
2771 dst
.savebmarks
<- src
.savebmarks
;
2772 dst
.memlimit
<- src
.memlimit
;
2773 dst
.proportional
<- src
.proportional
;
2774 dst
.texcount
<- src
.texcount
;
2775 dst
.sliceheight
<- src
.sliceheight
;
2776 dst
.thumbw
<- src
.thumbw
;
2780 let l = String.length
s in
2781 let b = Buffer.create
l in
2787 let h = Hashtbl.create
10 in
2788 let dc = { defconf with angle
= defconf.angle
} in
2789 let rec toplevel v t spos epos
=
2791 | Vdata
| Vcdata
| Vend
-> v
2792 | Vopen
("llppconfig", attrs
, closed
) ->
2795 else { v
with f = llppconfig
}
2797 error
"unexpected subelement at top level" s spos
2798 | Vclose tag
-> error
"unexpected close at top level" s spos
2800 and llppconfig v t spos epos
=
2802 | Vdata
| Vcdata
| Vend
-> v
2803 | Vopen
("defaults", attrs
, closed
) ->
2804 let c = config_of dc attrs
in
2808 else { v
with f = skip
"defaults" (fun () -> v
) }
2810 | Vopen
("doc", attrs
, closed
) ->
2811 let pathent, spage
, srely
, span
= doc_of attrs
in
2812 let path = unent pathent
2813 and pageno = fromstring int_of_string spos
"page" spage
0
2814 and rely
= fromstring float_of_string spos
"rely" srely
0.0
2815 and pan = fromstring int_of_string spos
"pan" span
0 in
2816 let c = config_of dc attrs
in
2817 let anchor = (pageno, rely
) in
2819 then (Hashtbl.add
h path (c, [], pan, anchor); v
)
2820 else { v
with f = doc
path pan anchor c [] }
2822 | Vopen
(tag
, _
, closed
) ->
2823 error
"unexpected subelement in llppconfig" s spos
2825 | Vclose
"llppconfig" -> { v
with f = toplevel }
2826 | Vclose tag
-> error
"unexpected close in llppconfig" s spos
2828 and doc
path pan anchor c bookmarks v t spos epos
=
2830 | Vdata
| Vcdata
-> v
2831 | Vend
-> error
"unexpected end of input in doc" s spos
2832 | Vopen
("bookmarks", attrs
, closed
) ->
2833 { v
with f = pbookmarks
path pan anchor c bookmarks }
2835 | Vopen
(tag
, _
, _
) ->
2836 error
"unexpected subelement in doc" s spos
2839 Hashtbl.add
h path (c, List.rev
bookmarks, pan, anchor);
2840 { v
with f = llppconfig
}
2842 | Vclose tag
-> error
"unexpected close in doc" s spos
2844 and pbookmarks
path pan anchor c bookmarks v t spos epos
=
2846 | Vdata
| Vcdata
-> v
2847 | Vend
-> error
"unexpected end of input in bookmarks" s spos
2848 | Vopen
("item", attrs
, closed
) ->
2849 let titleent, spage
, srely
= bookmark_of attrs
in
2850 let page = fromstring int_of_string spos
"page" spage
0
2851 and rely
= fromstring float_of_string spos
"rely" srely
0.0 in
2852 let bookmarks = (unent titleent, 0, page, rely
) :: bookmarks in
2854 then { v
with f = pbookmarks
path pan anchor c bookmarks }
2857 { v
with f = skip
"item" f }
2860 error
"unexpected subelement in bookmarks" s spos
2862 | Vclose
"bookmarks" ->
2863 { v
with f = doc
path pan anchor c bookmarks }
2865 | Vclose tag
-> error
"unexpected close in bookmarks" s spos
2867 and skip tag
f v t spos epos
=
2869 | Vdata
| Vcdata
-> v
2871 error
("unexpected end of input in skipped " ^ tag
) s spos
2872 | Vopen
(tag'
, _
, closed
) ->
2876 let f'
() = { v
with f = skip tag
f } in
2877 { v
with f = skip tag'
f'
}
2881 else error
("unexpected close in skipped " ^ tag
) s spos
2884 parse
{ f = toplevel; accu = () } s;
2890 let len = in_channel_length ic
in
2891 let s = String.create
len in
2892 really_input ic
s 0 len;
2895 | Parse_error
(msg
, s, pos
) ->
2896 let subs = subs s pos
in
2897 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
2898 failwith
("parse error: " ^
s)
2901 failwith
("config load error: " ^
Printexc.to_string exn
)
2907 let dir = Filename.concat
home ".config" in
2908 if Sys.is_directory
dir then dir else home
2911 Filename.concat
dir "llpp.conf"
2915 if Sys.file_exists
path
2918 (try Some
(open_in_bin
path)
2921 ("Error opening configuation file `" ^
path ^
"': " ^
2922 Printexc.to_string exn
);
2931 ("Error loading configuation from `" ^
path ^
"': " ^
2932 Printexc.to_string exn
);
2938 f (Hashtbl.create
0, defconf)
2943 let pc, pb
, px
, pa
=
2945 Hashtbl.find
h (Filename.basename
state.path)
2946 with Not_found
-> dc, [], 0, (0, 0.0)
2950 state.bookmarks <- pb
;
2952 cbput state.hists
.nav pa
;
2957 let add_attrs bb always
dc c =
2960 then Printf.bprintf bb
"\n %s='%b'" s a
2963 then Printf.bprintf bb
"\n %s='%d'" s a
2966 then Printf.bprintf bb
"\n %s='%f'" s (a*.100.)
2970 then dc.winw
, dc.winh
2972 match state.fullscreen
with
2974 | None
-> c.winw
, c.winh
2976 let zoom, presentation, interpagespace, showall
=
2978 then dc.zoom, dc.presentation, dc.interpagespace, dc.showall
2980 match state.mode
with
2981 | Birdseye
(bc
, _
, _
, _
, _
) ->
2982 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.showall
2983 | _
-> c.zoom, c.presentation, c.interpagespace, c.showall
2985 oi
"width" w dc.winw
;
2986 oi
"height" h dc.winh
;
2987 oi
"scroll-bar-width" c.scrollw
dc.scrollw
;
2988 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
2989 ob "case-insensitive-search" c.icase
dc.icase
;
2990 ob "preload" c.preload dc.preload;
2991 oi
"page-bias" c.pagebias
dc.pagebias
;
2992 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
2993 oi
"auto-scroll-step" c.autoscrollstep dc.autoscrollstep;
2994 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
2995 ob "crop-hack" c.crophack
dc.crophack
;
2996 ob "throttle" showall
dc.showall
;
2997 ob "highlight-links" c.hlinks
dc.hlinks
;
2998 ob "under-cursor-info" c.underinfo
dc.underinfo
;
2999 oi
"vertical-margin" interpagespace dc.interpagespace;
3000 oz
"zoom" zoom dc.zoom;
3001 ob "presentation" presentation dc.presentation;
3002 oi
"rotation-angle" c.angle
dc.angle
;
3003 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
3004 ob "proportional-display" c.proportional
dc.proportional
;
3005 oi
"pixmap-cache-size" c.memlimit
dc.memlimit
;
3006 oi
"texcount" c.texcount
dc.texcount
;
3007 oi
"slice-height" c.sliceheight
dc.sliceheight
;
3008 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
3012 let bb = Buffer.create
32768 in
3014 Buffer.add_string
bb "<llppconfig>\n<defaults ";
3015 add_attrs bb true dc dc;
3016 Buffer.add_string
bb "/>\n";
3018 let adddoc path pan anchor c bookmarks =
3019 if bookmarks == [] && c = dc && anchor = emptyanchor
3022 Printf.bprintf
bb "<doc path='%s'"
3023 (enent
path 0 (String.length
path));
3025 if anchor <> emptyanchor
3027 let n, y = anchor in
3028 Printf.bprintf
bb " page='%d'" n;
3029 Printf.bprintf
bb " rely='%f'" y;
3033 then Printf.bprintf
bb " pan='%d'" pan;
3035 add_attrs bb false dc c;
3037 begin match bookmarks with
3038 | [] -> Buffer.add_string
bb "/>\n"
3040 Buffer.add_string
bb ">\n<bookmarks>\n";
3041 List.iter
(fun (title, _level
, page, rely
) ->
3043 "<item title='%s' page='%d' rely='%f'/>\n"
3044 (enent
title 0 (String.length
title))
3048 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
3054 match state.mode
with
3055 | Birdseye
(_
, pan, _
, _
, _
) -> pan
3058 let basename = Filename.basename state.path in
3059 adddoc basename pan (getanchor ())
3062 if state.ascrollstep
> 0
3063 then state.ascrollstep
3064 else conf.autoscrollstep }
3065 (if conf.savebmarks
then state.bookmarks else []);
3067 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
3069 then adddoc path x y c bookmarks
3071 Buffer.add_string
bb "</llppconfig>";
3074 if Buffer.length
bb > 0
3077 let tmp = path ^
".tmp" in
3078 let oc = open_out_bin
tmp in
3079 Buffer.output_buffer
oc bb;
3081 Sys.rename
tmp path;
3084 ("error while saving configuration: " ^
Printexc.to_string exn
)
3091 ["-p", Arg.String
(fun s -> state.password
<- s) , " Set password"
3092 ;("-v", Arg.Unit
(fun () -> print_endline
Help.version
; exit
0),
3093 " Print version and exit")]
3095 (fun s -> state.path <- s)
3096 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
3098 if String.length
state.path = 0
3099 then (prerr_endline
"filename missing"; exit
1);
3103 let _ = Glut.init
Sys.argv
in
3104 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
3105 let () = Glut.initWindowSize
conf.winw
conf.winh
in
3106 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
3109 if Sys.os_type
= "Unix"
3111 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
3113 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
3114 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
3115 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
3116 Unix.bind
sock addr;
3118 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
3119 Unix.connect
csock addr;
3120 let ssock, _ = Unix.accept
sock in
3123 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
3124 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
3128 at_exit
(fun () -> Unix.shutdown
ssock Unix.SHUTDOWN_ALL
);
3132 let () = Glut.displayFunc
display in
3133 let () = Glut.reshapeFunc
reshape in
3134 let () = Glut.keyboardFunc
keyboard in
3135 let () = Glut.specialFunc
special in
3136 let () = Glut.idleFunc
(Some
idle) in
3137 let () = Glut.mouseFunc
mouse in
3138 let () = Glut.motionFunc
motion in
3139 let () = Glut.passiveMotionFunc
pmotion in
3141 init
ssock (conf.angle
, conf.proportional
, conf.texcount
, conf.sliceheight
);
3142 state.csock <- csock;
3143 state.ssock <- ssock;
3144 state.text <- "Opening " ^
state.path;
3145 writeopen state.path state.password
;
3149 let rec handlelablglutbug () =
3152 with Glut.BadEnum
"key in special_of_int" ->
3153 showtext '
!'
" LablGlut bug: special key not recognized";
3154 handlelablglutbug ()
3156 handlelablglutbug ();