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)
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 = function
1064 | l :: _
when l.pagey = 0 -> l.pageno
1065 | _
:: rest
-> fold 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, "");
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");
1524 begin match state.fullscreen
with
1526 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
1529 state.fullscreen
<- None
;
1534 gotoy_and_clear_text 0
1537 search state.searchpattern
true
1540 search state.searchpattern
false
1543 begin match state.layout with
1546 gotoy_and_clear_text (getpagey l.pageno)
1550 begin match List.rev
state.layout with
1553 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
1554 gotoy_and_clear_text (getpagey pageno)
1558 begin match state.layout with
1561 let pageno = max
0 (l.pageno-1) in
1562 gotoy_and_clear_text (getpagey pageno)
1567 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
1569 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
1571 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
1575 else (100. *. (float state.y /. float maxy)) in
1578 Printf.sprintf
"Page %d of %d %.2f%%"
1579 (fn+1) state.pagecount
percent
1582 "Pages %d-%d of %d %.2f%%"
1583 (fn+1) (ln
+1) state.pagecount
percent
1588 begin match state.layout with
1591 doreshape (l.pagew
+ conf.scrollw
) l.pageh
;
1592 Glut.postRedisplay
();
1596 enterbookmarkmode ()
1606 match state.layout with
1609 (s, 0, l.pageno, float l.pagey /. float l.pageh
)
1613 enttext ('~'
, "", None
, textentry, ondone)
1617 showtext ' '
"Quick bookmark added";
1620 begin match state.layout with
1622 let rect = getpdimrect
l.pagedimno
in
1626 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
1627 truncate
(1.2 *. (rect.(3) -. rect.(0))))
1629 (truncate
(rect.(1) -. rect.(0)),
1630 truncate
(rect.(3) -. rect.(0)))
1634 doreshape (w + conf.scrollw
) (h + conf.interpagespace)
1636 Glut.postRedisplay
();
1642 reinit (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
1647 (min
(state.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 1.0);
1648 Glut.postRedisplay
()
1650 | 'k'
-> gotoy (clamp (-conf.scrollstep
))
1651 | 'j'
-> gotoy (clamp conf.scrollstep
)
1653 | '
r'
-> opendoc state.path
state.password
1656 vlog "huh? %d %c" key
(Char.chr key
);
1659 let textentrykeyboard ~key ~x ~
y ((c, text, opthist
, onkey
, ondone), mode
) =
1661 state.mode
<- Textentry
(te
, mode
);
1664 Glut.postRedisplay
()
1666 match Char.unsafe_chr key
with
1668 let len = String.length
text in
1672 Glut.postRedisplay
();
1675 let s = String.sub
text 0 (len - 1) in
1676 enttext (c, s, opthist
, onkey
, ondone)
1682 Glut.postRedisplay
()
1685 begin match opthist
with
1687 | Some
(_
, onhistcancel
) -> onhistcancel
()
1690 Glut.postRedisplay
()
1693 begin match onkey
text key
with
1697 Glut.postRedisplay
()
1700 enttext (c, text, opthist
, onkey
, ondone);
1704 Glut.postRedisplay
()
1707 state.mode
<- Textentry
(te
, mode
);
1708 Glut.postRedisplay
()
1712 let birdseyekeyboard ~key ~x ~
y ((_
, _
, pageno, _
, anchor) as beye
) =
1715 leavebirdseye beye
true
1718 let y, h = getpageyh pageno in
1719 let top = (conf.winh
- h) / 2 in
1720 gotoy (max
0 (y - top))
1723 leavebirdseye beye
false
1726 viewkeyboard ~key ~x ~
y
1729 let outlinekeyboard ~key ~x ~
y (allowdel
, active, first
, outlines, qsearch
) =
1730 let narrow outlines pattern
=
1731 let reopt = try Some
(Str.regexp_case_fold pattern
) with _
-> None
in
1735 let rec fold accu n =
1739 let (s, _
, _
, _
) as o = outlines.(n) in
1741 if (try ignore
(Str.search_forward re
s 0); true
1742 with Not_found
-> false)
1748 let matched = fold [] (Array.length
outlines - 1) in
1749 if matched = [] then None
else Some
(Array.of_list
matched)
1751 let search active pattern
incr =
1754 if n = Array.length
outlines || n = -1
1757 let (s, _
, _
, _
) = outlines.(n) in
1759 (try ignore
(Str.search_forward re
s 0); true
1760 with Not_found
-> false)
1762 else loop (n + incr)
1767 let re = Str.regexp_case_fold pattern
in
1773 let firstof active = max
0 (active - maxoutlinerows () / 2) in
1776 if String.length qsearch
= 0
1780 Glut.postRedisplay
();
1784 state.mode
<- Outline
(allowdel
, active, first
, outlines, "");
1785 Glut.postRedisplay
();
1789 let incr = if key
= 18 then -1 else 1 in
1791 match search (active + incr) qsearch
incr with
1793 state.text <- qsearch ^
" [not found]";
1796 state.text <- qsearch
;
1797 active, firstof active
1799 state.mode
<- Outline
(allowdel
, active, first
, outlines, qsearch
);
1800 Glut.postRedisplay
();
1803 let len = String.length qsearch
in
1810 state.mode
<- Outline
(allowdel
, active, first
, outlines, "");
1813 let qsearch = String.sub
qsearch 0 (len - 1) in
1815 match search active qsearch ~
-1 with
1817 state.text <- qsearch ^
" [not found]";
1820 state.text <- qsearch;
1821 active, firstof active
1823 state.mode
<- Outline
(allowdel
, active, first
, outlines, qsearch);
1825 Glut.postRedisplay
()
1828 if active < Array.length
outlines
1830 let (_
, _
, n, t
) = outlines.(active) in
1835 if allowdel
then state.bookmarks <- Array.to_list
outlines;
1837 Glut.postRedisplay
();
1839 | _
when key
>= 32 && key
< 127 ->
1840 let pattern = addchar qsearch (Char.chr key
) in
1842 match search active pattern 1 with
1844 state.text <- pattern ^
" [not found]";
1847 state.text <- pattern;
1848 active, firstof active
1850 state.mode
<- Outline
(allowdel
, active, first
, outlines, pattern);
1851 Glut.postRedisplay
()
1853 | 14 when not allowdel
-> (* ctrl-n *)
1854 if String.length
qsearch > 0
1856 let optoutlines = narrow outlines qsearch in
1857 begin match optoutlines with
1858 | None
-> state.text <- "can't narrow"
1860 state.mode
<- Outline
(allowdel
, 0, 0, outlines, qsearch);
1861 match state.outlines with
1864 state.outlines <- Onarrow
(qsearch, outlines, a)
1865 | Onarrow
(pat
, a, b) ->
1866 state.outlines <- Onarrow
(qsearch, outlines, b)
1869 Glut.postRedisplay
()
1871 | 21 when not allowdel
-> (* ctrl-u *)
1873 match state.outlines with
1876 let a = Array.of_list
(List.rev
l) in
1877 state.outlines <- Oarray
a;
1879 | Onarrow
(pat
, a, b) ->
1880 state.outlines <- Oarray
b;
1884 state.mode
<- Outline
(allowdel
, 0, 0, outline, qsearch);
1885 Glut.postRedisplay
()
1888 state.mode
<- Outline
1889 (allowdel
, active, firstof active, outlines, qsearch);
1890 Glut.postRedisplay
()
1892 | 127 when allowdel
->
1893 let len = Array.length
outlines - 1 in
1897 state.bookmarks <- [];
1900 let bookmarks = Array.init
len
1902 let i = if i >= active then i + 1 else i in
1914 Glut.postRedisplay
()
1916 | _
-> dolog "unknown key %d" key
1919 let keyboard ~key ~x ~
y =
1924 match state.mode
with
1925 | Outline
outline -> outlinekeyboard ~key ~x ~
y outline
1926 | Textentry
textentry -> textentrykeyboard ~key ~x ~
y textentry
1927 | Birdseye birdseye
-> birdseyekeyboard ~key ~x ~
y birdseye
1928 | View
-> viewkeyboard ~key ~x ~
y
1931 let birdseyespecial key x
y (conf, leftx
, pageno, hooverpageno
, anchor) =
1934 let pageno = max
0 (pageno - 1) in
1935 let rec loop = function
1936 | [] -> gotopage1 pageno 0
1937 | l :: _
when l.pageno = pageno ->
1938 if l.pagedispy
>= 0 && l.pagey = 0
1939 then Glut.postRedisplay
()
1940 else gotopage1 pageno 0
1941 | _
:: rest
-> loop rest
1944 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
1947 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
1948 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
1949 let rec loop = function
1951 let y, h = getpageyh pageno in
1952 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
1954 | l :: rest
when l.pageno = pageno ->
1955 if l.pagevh != l.pageh
1956 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
1957 else Glut.postRedisplay
()
1958 | l :: rest
-> loop rest
1962 | Glut.KEY_PAGE_UP
->
1963 begin match state.layout with
1967 state.mode
<- Birdseye
(
1968 conf, leftx
, l.pageno, hooverpageno
, anchor
1970 gotopage1 l.pageno 0;
1973 let layout = layout (state.y-conf.winh
) conf.winh
in
1975 | [] -> gotoy (clamp (-conf.winh
))
1977 state.mode
<- Birdseye
(
1978 conf, leftx
, l.pageno, hooverpageno
, anchor
1980 gotopage1 l.pageno 0
1983 | [] -> gotoy (clamp (-conf.winh
))
1986 | Glut.KEY_PAGE_DOWN
->
1987 begin match List.rev
state.layout with
1989 let layout = layout (state.y + conf.winh
) conf.winh
in
1990 begin match layout with
1992 let incr = l.pageh
- l.pagevh in
1997 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
1999 Glut.postRedisplay
();
2001 else gotoy (clamp (incr + conf.interpagespace*2));
2005 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
2006 gotopage1 l.pageno 0;
2009 | [] -> gotoy (clamp conf.winh
)
2013 state.mode
<- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
2017 let pageno = state.pagecount
- 1 in
2018 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2019 if not
(pagevisible state.layout pageno)
2022 match List.rev
state.pdims
with
2024 | (_
, _
, h, _
) :: _
-> h
2026 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
2027 else Glut.postRedisplay
();
2031 let setautoscrollspeed goingdown
=
2032 let incr = max
1 (state.ascrollstep
/ 2) in
2033 let astep = max
1 (state.ascrollstep
+ (if goingdown
then incr else -incr)) in
2034 state.ascrollstep
<- astep;
2037 let special ~key ~x ~
y =
2038 match state.mode
with
2039 | View
| (Birdseye _
) when key
= Glut.KEY_F9
->
2043 birdseyespecial key x
y vals
2045 | View
when key
= Glut.KEY_F1
->
2049 if state.ascrollstep
> 0 && (key
= Glut.KEY_DOWN
|| key
= Glut.KEY_UP
)
2050 then setautoscrollspeed (key
= Glut.KEY_DOWN
)
2054 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
2055 | Glut.KEY_UP
-> clamp (-conf.scrollstep
)
2056 | Glut.KEY_DOWN
-> clamp conf.scrollstep
2057 | Glut.KEY_PAGE_UP
->
2058 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2060 match state.layout with
2062 | l :: _
-> state.y - l.pagey
2065 | Glut.KEY_PAGE_DOWN
->
2066 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2068 match List.rev
state.layout with
2070 | l :: _
-> getpagey l.pageno
2073 | Glut.KEY_HOME
-> addnav (); 0
2076 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
2078 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
2079 state.x
<- state.x
- 10;
2081 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
2082 state.x
<- state.x
+ 10;
2087 gotoy_and_clear_text y
2090 ((c, s, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2093 | Glut.KEY_UP
-> action HCprev
2094 | Glut.KEY_DOWN
-> action HCnext
2095 | Glut.KEY_HOME
-> action HCfirst
2096 | Glut.KEY_END
-> action HClast
2099 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2100 Glut.postRedisplay
()
2104 | Outline
(allowdel
, active, first
, outlines, qsearch) ->
2105 let maxrows = maxoutlinerows () in
2106 let calcfirst first
active =
2109 let rows = active - first
in
2110 if rows > maxrows then active - maxrows else first
2114 let active = active + incr in
2115 let active = max
0 (min
active (Array.length
outlines - 1)) in
2116 let first = calcfirst first active in
2117 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch);
2118 Glut.postRedisplay
()
2120 let updownlevel incr =
2121 let len = Array.length
outlines in
2122 let (_
, curlevel
, _
, _
) = outlines.(active) in
2124 if i = len then i-1 else if i = -1 then 0 else
2125 let (_
, l, _
, _
) = outlines.(i) in
2126 if l != curlevel
then i else flow (i+incr)
2128 let active = flow active in
2129 let first = calcfirst first active in
2130 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch);
2131 Glut.postRedisplay
()
2134 | Glut.KEY_UP
-> navigate ~
-1
2135 | Glut.KEY_DOWN
-> navigate 1
2136 | Glut.KEY_PAGE_UP
-> navigate ~
-maxrows
2137 | Glut.KEY_PAGE_DOWN
-> navigate maxrows
2139 | Glut.KEY_RIGHT
when not allowdel
-> updownlevel 1
2140 | Glut.KEY_LEFT
when not allowdel
-> updownlevel ~
-1
2143 state.mode
<- Outline
(allowdel
, 0, 0, outlines, qsearch);
2144 Glut.postRedisplay
()
2147 let active = Array.length
outlines - 1 in
2148 let first = max
0 (active - maxrows) in
2149 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch);
2150 Glut.postRedisplay
()
2155 let drawplaceholder l =
2156 let margin = state.x
+ (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2158 (float l.pagex
, float l.pagedispy
)
2159 (float (l.pagew
+ l.pagex
), float (l.pagedispy
+ l.pagevh))
2161 let x = float (if margin < 0 then -margin else l.pagex
)
2162 and y = float (l.pagedispy
+ 13) in
2163 let font = Glut.BITMAP_8_BY_13
in
2164 GlDraw.color
(0.0, 0.0, 0.0);
2165 GlPix.raster_pos ~
x ~
y ();
2166 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c))
2167 ("Loading " ^ string_of_int
(l.pageno + 1));
2170 let now () = Unix.gettimeofday
();;
2174 match state.mode
with
2175 | Textentry _
-> scalecolor 0.4
2176 | View
| Outline _
-> scalecolor 1.0
2177 | Birdseye
(_
, _
, pageno, hooverpageno
, _
) ->
2178 if l.pageno = pageno
2181 if l.pageno = hooverpageno
2187 begin match getopaque l.pageno with
2188 | Some
(opaque, _
) when validopaque opaque ->
2190 draw
(l.pagedispy
, l.pagew
, l.pagevh, l.pagey, conf.hlinks
)
2194 vlog "draw %d %f sec" l.pageno d;
2202 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
2203 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2204 let sh = float conf.winh
/. sh in
2205 let sh = max
sh (float conf.scrollh
) in
2208 if state.y = state.maxy
2210 else float y /. float maxy
2212 let position = (float conf.winh
-. sh) *. percent in
2215 if position +. sh > float conf.winh
2216 then float conf.winh
-. sh
2222 let scrollindicator () =
2223 GlDraw.color (0.64 , 0.64, 0.64);
2225 (float (conf.winw
- conf.scrollw
), 0.)
2226 (float conf.winw
, float conf.winh
)
2228 GlDraw.color (0.0, 0.0, 0.0);
2230 let position, sh = scrollph state.y in
2232 (float (conf.winw
- conf.scrollw
), position)
2233 (float conf.winw
, position +. sh)
2237 let showsel margin =
2238 match state.mstate
with
2239 | Mnone
| Mscroll _
| Mpan _
| Mzoom _
->
2242 | Msel
((x0
, y0
), (x1
, y1
)) ->
2243 let rec loop = function
2245 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
2246 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
2248 match getopaque l.pageno with
2249 | Some
(opaque, _
) when validopaque opaque ->
2250 let oy = -l.pagey + l.pagedispy
in
2252 (x0
- margin - state.x, y0
,
2253 x1
- margin - state.x, y1
) oy;
2263 let panx = float state.x in
2265 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
2266 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2268 (fun (pageno, c, (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
2270 if l.pageno = pageno
2272 let d = float (l.pagedispy
- l.pagey) in
2273 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
2274 GlDraw.begins `quads
;
2276 GlDraw.vertex2
(x0
+.panx, y0
+.d);
2277 GlDraw.vertex2
(x1
+.panx, y1
+.d);
2278 GlDraw.vertex2
(x2
+.panx, y2
+.d);
2279 GlDraw.vertex2
(x3
+.panx, y3
+.d);
2289 let showoutline () =
2290 match state.mode
with
2291 | Outline
(allowdel
, active, first, outlines, qsearch) ->
2293 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2294 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2295 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2298 GlDraw.color (1., 1., 1.);
2299 let font = Glut.BITMAP_9_BY_15
in
2300 let draw_string x y s =
2301 GlPix.raster_pos ~
x ~
y ();
2302 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c)) s
2305 if row
= Array.length
outlines || (row
- first) * 16 > conf.winh
2308 let (s, l, _
, _
) = outlines.(row
) in
2309 let y = (row
- first) * 16 in
2314 GlDraw.polygon_mode `both `
line;
2315 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2316 GlDraw.color (1., 1., 1.) ~alpha
:0.9;
2317 GlDraw.rect (0., float (y + 1))
2318 (float (conf.winw
- 1), float (y + 18));
2319 GlDraw.polygon_mode `both `fill
;
2321 GlDraw.color (1., 1., 1.);
2323 draw_string (float x) (float (y + 16)) s;
2333 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2334 GlDraw.viewport
margin 0 state.w conf.winh
;
2336 GlClear.color (scalecolor 0.5);
2337 GlClear.clear
[`
color];
2340 Gl.enable `scissor_test
;
2341 GlMisc.scissor
0 0 (conf.winw
- conf.scrollw
) conf.winh
;
2343 List.iter
drawpage state.layout;
2346 Gl.disable `scissor_test
2350 let x = -.float state.x in
2351 GlMat.translate ~
x ();
2355 GlDraw.viewport
0 0 conf.winw
conf.winh
;
2360 Glut.swapBuffers
();
2364 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2365 let x = x - margin - state.x in
2366 let rec f = function
2368 begin match getopaque l.pageno with
2369 | Some
(opaque, _
) when validopaque opaque ->
2370 let y = y - l.pagedispy
in
2373 let y = l.pagey + y in
2374 let x = x - l.pagex
in
2375 match whatsunder
opaque x y with
2388 let viewmouse button bstate
x y =
2390 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2391 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2393 match state.mstate
with
2394 | Mzoom
(oldn
, i) ->
2402 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
2404 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
2406 let zoom = conf.zoom +. incr in
2408 state.mstate
<- Mzoom
(n, 0);
2410 state.mstate
<- Mzoom
(n, i+1);
2412 else state.mstate
<- Mzoom
(n, 0)
2414 | _
-> state.mstate
<- Mzoom
(n, 0)
2417 if state.ascrollstep
> 0
2419 setautoscrollspeed (n=4)
2423 then -conf.scrollstep
2424 else conf.scrollstep
2426 let incr = incr * 2 in
2427 let y = clamp incr in
2428 gotoy_and_clear_text y
2431 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
2432 if bstate
= Glut.DOWN
2434 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
2435 state.mstate
<- Mpan
(x, y)
2438 state.mstate
<- Mnone
2440 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollw
->
2441 if bstate
= Glut.DOWN
2443 let position, sh = scrollph state.y in
2444 if y > truncate
position && y < truncate
(position +. sh)
2446 state.mstate
<- Mscroll
2448 let percent = float y /. float conf.winh
in
2449 let desty = truncate
(float (state.maxy - conf.winh
) *. percent) in
2451 state.mstate
<- Mscroll
2453 state.mstate
<- Mnone
2455 | Glut.LEFT_BUTTON
->
2456 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
2457 begin match dest with
2458 | Ulinkgoto
(pageno, top) ->
2462 gotopage1 pageno top;
2468 | Unone
when bstate
= Glut.DOWN
->
2469 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
2470 state.mstate
<- Mpan
(x, y);
2472 | Unone
| Utext _
->
2473 if bstate
= Glut.DOWN
2475 if conf.angle
mod 360 = 0
2477 state.mstate
<- Msel
((x, y), (x, y));
2478 Glut.postRedisplay
()
2482 match state.mstate
with
2485 | Mzoom _
| Mscroll
->
2486 state.mstate
<- Mnone
2489 Glut.setCursor
Glut.CURSOR_INHERIT
;
2490 state.mstate
<- Mnone
2492 | Msel
((x0
, y0
), (x1
, y1
)) ->
2494 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
2495 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
2497 match getopaque l.pageno with
2498 | Some
(opaque, _
) when validopaque opaque ->
2502 List.iter
f state.layout;
2503 copysel
""; (* ugly *)
2504 Glut.setCursor
Glut.CURSOR_INHERIT
;
2505 state.mstate
<- Mnone
;
2512 let birdseyemouse button bstate
x y
2513 (conf, leftx
, pageno, hooverpageno
, anchor) =
2515 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2516 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2517 let rec loop = function
2520 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
2521 && x > margin && x < margin + l.pagew
2523 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
2528 | Glut.OTHER_BUTTON _
-> viewmouse button bstate
x y
2532 let mouse bstate button
x y =
2533 match state.mode
with
2534 | View
-> viewmouse button bstate
x y
2535 | Birdseye beye
-> birdseyemouse button bstate
x y beye
2540 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
2543 match state.mode
with
2546 match state.mstate
with
2547 | Mzoom _
| Mnone
-> ()
2552 state.mstate
<- Mpan
(x, y);
2553 if conf.zoom > 1.0 then state.x <- state.x + dx;
2555 gotoy_and_clear_text y
2558 state.mstate
<- Msel
(a, (x, y));
2559 Glut.postRedisplay
()
2562 let y = min
conf.winh
(max
0 y) in
2563 let percent = float y /. float conf.winh
in
2564 let y = truncate
(float (state.maxy - conf.winh
) *. percent) in
2565 gotoy_and_clear_text y
2569 match state.mode
with
2570 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
2571 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2572 let rec loop = function
2574 if hooverpageno
!= -1
2576 state.mode
<- Birdseye
(conf, leftx
, pageno, -1, anchor);
2577 Glut.postRedisplay
();
2580 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
2581 && x > margin && x < margin + l.pagew
2583 state.mode
<- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
2584 Glut.postRedisplay
();
2592 match state.mstate
with
2594 begin match getunder x y with
2595 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
2597 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
2598 Glut.setCursor
Glut.CURSOR_INFO
2599 | Ulinkgoto
(page
, y) ->
2601 then showtext 'p'
("age: " ^ string_of_int page
);
2602 Glut.setCursor
Glut.CURSOR_INFO
2604 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
2605 Glut.setCursor
Glut.CURSOR_TEXT
2608 | Mpan _
| Msel _
| Mzoom _
| Mscroll
->
2619 match Sys.os_type
with
2620 | "Win32" -> Sys.getenv
"HOMEPATH"
2621 | _
-> Sys.getenv
"HOME"
2624 ("Can not determine home directory location: " ^
2625 Printexc.to_string exn
);
2629 let config_of c attrs
=
2633 | "scroll-bar-width" -> { c with scrollw
= max
0 (int_of_string v
) }
2634 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string v
) }
2635 | "case-insensitive-search" -> { c with icase
= bool_of_string v
}
2636 | "preload" -> { c with preload = bool_of_string v
}
2637 | "page-bias" -> { c with pagebias
= int_of_string v
}
2638 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string v
) }
2639 | "auto-scroll-step" ->
2640 { c with autoscrollstep = max
0 (int_of_string v
) }
2641 | "max-height-fit" -> { c with maxhfit
= bool_of_string v
}
2642 | "crop-hack" -> { c with crophack
= bool_of_string v
}
2643 | "throttle" -> { c with showall
= bool_of_string v
}
2644 | "highlight-links" -> { c with hlinks
= bool_of_string v
}
2645 | "under-cursor-info" -> { c with underinfo
= bool_of_string v
}
2646 | "vertical-margin" ->
2647 { c with interpagespace = max
0 (int_of_string v
) }
2649 let zoom = float_of_string v
/. 100. in
2650 let zoom = max
0.01 (min
2.2 zoom) in
2651 { c with zoom = zoom }
2652 | "presentation" -> { c with presentation = bool_of_string v
}
2653 | "rotation-angle" -> { c with angle
= int_of_string v
}
2654 | "width" -> { c with winw
= max
20 (int_of_string v
) }
2655 | "height" -> { c with winh
= max
20 (int_of_string v
) }
2656 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string v
}
2657 | "proportional-display" -> { c with proportional
= bool_of_string v
}
2658 | "pixmap-cache-size" -> { c with memlimit
= max
2 (int_of_string v
) }
2659 | "tex-count" -> { c with texcount
= max
1 (int_of_string v
) }
2660 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string v
) }
2661 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string v
) }
2664 prerr_endline
("Error processing attribute (`" ^
2665 k ^
"'=`" ^ v ^
"'): " ^
Printexc.to_string exn
);
2668 let rec fold c = function
2671 let c = apply c k v
in
2677 let fromstring f pos
n v
d =
2680 dolog "Error processing attribute (%S=%S) at %d\n%s"
2681 n v pos
(Printexc.to_string exn
)
2686 let bookmark_of attrs
=
2687 let rec fold title page rely
= function
2688 | ("title", v
) :: rest
-> fold v page rely rest
2689 | ("page", v
) :: rest
-> fold title v rely rest
2690 | ("rely", v
) :: rest
-> fold title page v rest
2691 | _
:: rest
-> fold title page rely rest
2692 | [] -> title, page
, rely
2694 fold "invalid" "0" "0" attrs
2698 let rec fold path page rely pan
= function
2699 | ("path", v
) :: rest
-> fold v page rely pan rest
2700 | ("page", v
) :: rest
-> fold path v rely pan rest
2701 | ("rely", v
) :: rest
-> fold path page v pan rest
2702 | ("pan", v
) :: rest
-> fold path page rely v rest
2703 | _
:: rest
-> fold path page rely pan rest
2704 | [] -> path
, page
, rely
, pan
2706 fold "" "0" "0" "0" attrs
2709 let setconf dst src
=
2710 dst
.scrollw
<- src
.scrollw
;
2711 dst
.scrollh
<- src
.scrollh
;
2712 dst
.icase
<- src
.icase
;
2713 dst
.preload <- src
.preload;
2714 dst
.pagebias
<- src
.pagebias
;
2715 dst
.verbose
<- src
.verbose
;
2716 dst
.scrollstep
<- src
.scrollstep
;
2717 dst
.maxhfit
<- src
.maxhfit
;
2718 dst
.crophack
<- src
.crophack
;
2719 dst
.autoscrollstep <- src
.autoscrollstep;
2720 dst
.showall
<- src
.showall
;
2721 dst
.hlinks
<- src
.hlinks
;
2722 dst
.underinfo
<- src
.underinfo
;
2723 dst
.interpagespace <- src
.interpagespace;
2724 dst
.zoom <- src
.zoom;
2725 dst
.presentation <- src
.presentation;
2726 dst
.angle
<- src
.angle
;
2727 dst
.winw
<- src
.winw
;
2728 dst
.winh
<- src
.winh
;
2729 dst
.savebmarks
<- src
.savebmarks
;
2730 dst
.memlimit
<- src
.memlimit
;
2731 dst
.proportional
<- src
.proportional
;
2732 dst
.texcount
<- src
.texcount
;
2733 dst
.sliceheight
<- src
.sliceheight
;
2734 dst
.thumbw
<- src
.thumbw
;
2738 let l = String.length
s in
2739 let b = Buffer.create
l in
2745 let h = Hashtbl.create
10 in
2746 let dc = { defconf with angle
= defconf.angle
} in
2747 let rec toplevel v t spos epos
=
2749 | Vdata
| Vcdata
| Vend
-> v
2750 | Vopen
("llppconfig", attrs
, closed
) ->
2753 else { v
with f = llppconfig
}
2755 error
"unexpected subelement at top level" s spos
2756 | Vclose tag
-> error
"unexpected close at top level" s spos
2758 and llppconfig v t spos epos
=
2760 | Vdata
| Vcdata
| Vend
-> v
2761 | Vopen
("defaults", attrs
, closed
) ->
2762 let c = config_of dc attrs
in
2766 else { v
with f = skip
"defaults" (fun () -> v
) }
2768 | Vopen
("doc", attrs
, closed
) ->
2769 let pathent, spage
, srely
, span
= doc_of attrs
in
2770 let path = unent pathent
2771 and pageno = fromstring int_of_string spos
"page" spage
0
2772 and rely
= fromstring float_of_string spos
"rely" srely
0.0
2773 and pan
= fromstring int_of_string spos
"pan" span
0 in
2774 let c = config_of dc attrs
in
2775 let anchor = (pageno, rely
) in
2777 then (Hashtbl.add
h path (c, [], pan
, anchor); v
)
2778 else { v
with f = doc
path pan
anchor c [] }
2780 | Vopen
(tag
, _
, closed
) ->
2781 error
"unexpected subelement in llppconfig" s spos
2783 | Vclose
"llppconfig" -> { v
with f = toplevel }
2784 | Vclose tag
-> error
"unexpected close in llppconfig" s spos
2786 and doc
path pan
anchor c bookmarks v t spos epos
=
2788 | Vdata
| Vcdata
-> v
2789 | Vend
-> error
"unexpected end of input in doc" s spos
2790 | Vopen
("bookmarks", attrs
, closed
) ->
2791 { v
with f = pbookmarks
path pan
anchor c bookmarks }
2793 | Vopen
(tag
, _
, _
) ->
2794 error
"unexpected subelement in doc" s spos
2797 Hashtbl.add
h path (c, List.rev
bookmarks, pan
, anchor);
2798 { v
with f = llppconfig
}
2800 | Vclose tag
-> error
"unexpected close in doc" s spos
2802 and pbookmarks
path pan
anchor c bookmarks v t spos epos
=
2804 | Vdata
| Vcdata
-> v
2805 | Vend
-> error
"unexpected end of input in bookmarks" s spos
2806 | Vopen
("item", attrs
, closed
) ->
2807 let titleent, spage
, srely
= bookmark_of attrs
in
2808 let page = fromstring int_of_string spos
"page" spage
0
2809 and rely
= fromstring float_of_string spos
"rely" srely
0.0 in
2810 let bookmarks = (unent titleent, 0, page, rely
) :: bookmarks in
2812 then { v
with f = pbookmarks
path pan
anchor c bookmarks }
2815 { v
with f = skip
"item" f }
2818 error
"unexpected subelement in bookmarks" s spos
2820 | Vclose
"bookmarks" ->
2821 { v
with f = doc
path pan
anchor c bookmarks }
2823 | Vclose tag
-> error
"unexpected close in bookmarks" s spos
2825 and skip tag
f v t spos epos
=
2827 | Vdata
| Vcdata
-> v
2829 error
("unexpected end of input in skipped " ^ tag
) s spos
2830 | Vopen
(tag'
, _
, closed
) ->
2834 let f'
() = { v
with f = skip tag
f } in
2835 { v
with f = skip tag'
f'
}
2839 else error
("unexpected close in skipped " ^ tag
) s spos
2842 parse
{ f = toplevel; accu = () } s;
2848 let len = in_channel_length ic
in
2849 let s = String.create
len in
2850 really_input ic
s 0 len;
2853 | Parse_error
(msg
, s, pos
) ->
2854 let subs = subs s pos
in
2855 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
2856 failwith
("parse error: " ^
s)
2859 failwith
("config load error: " ^
Printexc.to_string exn
)
2865 let dir = Filename.concat
home ".config" in
2866 if Sys.is_directory
dir then dir else home
2869 Filename.concat
dir "llpp.conf"
2873 if Sys.file_exists
path
2876 (try Some
(open_in_bin
path)
2879 ("Error opening configuation file `" ^
path ^
"': " ^
2880 Printexc.to_string exn
);
2889 ("Error loading configuation from `" ^
path ^
"': " ^
2890 Printexc.to_string exn
);
2896 f (Hashtbl.create
0, defconf)
2901 let pc, pb
, px
, pa
=
2903 Hashtbl.find
h (Filename.basename
state.path)
2904 with Not_found
-> dc, [], 0, (0, 0.0)
2908 state.bookmarks <- pb
;
2910 cbput state.hists
.nav pa
;
2915 let add_attrs bb always
dc c =
2918 then Printf.bprintf bb
"\n %s='%b'" s a
2921 then Printf.bprintf bb
"\n %s='%d'" s a
2924 then Printf.bprintf bb
"\n %s='%f'" s (a*.100.)
2928 then dc.winw
, dc.winh
2930 match state.fullscreen
with
2932 | None
-> c.winw
, c.winh
2934 let zoom, presentation, interpagespace, showall
=
2936 then dc.zoom, dc.presentation, dc.interpagespace, dc.showall
2938 match state.mode
with
2939 | Birdseye
(bc
, _
, _
, _
, _
) ->
2940 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.showall
2941 | _
-> c.zoom, c.presentation, c.interpagespace, c.showall
2943 oi
"width" w dc.winw
;
2944 oi
"height" h dc.winh
;
2945 oi
"scroll-bar-width" c.scrollw
dc.scrollw
;
2946 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
2947 ob "case-insensitive-search" c.icase
dc.icase
;
2948 ob "preload" c.preload dc.preload;
2949 oi
"page-bias" c.pagebias
dc.pagebias
;
2950 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
2951 oi
"auto-scroll-step" c.autoscrollstep dc.autoscrollstep;
2952 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
2953 ob "crop-hack" c.crophack
dc.crophack
;
2954 ob "throttle" showall
dc.showall
;
2955 ob "highlight-links" c.hlinks
dc.hlinks
;
2956 ob "under-cursor-info" c.underinfo
dc.underinfo
;
2957 oi
"vertical-margin" interpagespace dc.interpagespace;
2958 oz
"zoom" zoom dc.zoom;
2959 ob "presentation" presentation dc.presentation;
2960 oi
"rotation-angle" c.angle
dc.angle
;
2961 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
2962 ob "proportional-display" c.proportional
dc.proportional
;
2963 oi
"pixmap-cache-size" c.memlimit
dc.memlimit
;
2964 oi
"texcount" c.texcount
dc.texcount
;
2965 oi
"slice-height" c.sliceheight
dc.sliceheight
;
2966 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
2970 let bb = Buffer.create
32768 in
2972 Buffer.add_string
bb "<llppconfig>\n<defaults ";
2973 add_attrs bb true dc dc;
2974 Buffer.add_string
bb "/>\n";
2976 let adddoc path pan
anchor c bookmarks =
2977 if bookmarks == [] && c = dc && anchor = emptyanchor
2980 Printf.bprintf
bb "<doc path='%s'"
2981 (enent
path 0 (String.length
path));
2983 if anchor <> emptyanchor
2985 let n, y = anchor in
2986 Printf.bprintf
bb " page='%d'" n;
2987 Printf.bprintf
bb " rely='%f'" y;
2991 then Printf.bprintf
bb " pan='%d'" pan
;
2993 add_attrs bb false dc c;
2995 begin match bookmarks with
2996 | [] -> Buffer.add_string
bb "/>\n"
2998 Buffer.add_string
bb ">\n<bookmarks>\n";
2999 List.iter
(fun (title, _level
, page, rely
) ->
3001 "<item title='%s' page='%d' rely='%f'/>\n"
3002 (enent
title 0 (String.length
title))
3006 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
3012 match state.mode
with
3013 | Birdseye
(_
, pan, _
, _
, _
) -> pan
3016 let basename = Filename.basename state.path in
3017 adddoc basename pan (getanchor ())
3020 if state.ascrollstep
> 0
3021 then state.ascrollstep
3022 else conf.autoscrollstep }
3023 (if conf.savebmarks
then state.bookmarks else []);
3025 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
3027 then adddoc path x y c bookmarks
3029 Buffer.add_string
bb "</llppconfig>";
3032 if Buffer.length
bb > 0
3035 let tmp = path ^
".tmp" in
3036 let oc = open_out_bin
tmp in
3037 Buffer.output_buffer
oc bb;
3039 Sys.rename
tmp path;
3042 ("error while saving configuration: " ^
Printexc.to_string exn
)
3048 ["-p", Arg.String
(fun s -> state.password
<- s) , "password"
3049 ;("-v", Arg.Unit
(fun () -> print_endline
Help.version
; exit
0),
3051 (fun s -> state.path <- s)
3052 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\noptions:")
3054 if String.length
state.path = 0
3055 then (prerr_endline
"filename missing"; exit
1);
3059 let _ = Glut.init
Sys.argv
in
3060 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
3061 let () = Glut.initWindowSize
conf.winw
conf.winh
in
3062 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
3065 if Sys.os_type
= "Unix"
3067 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
3069 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
3070 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
3071 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
3072 Unix.bind
sock addr;
3074 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
3075 Unix.connect
csock addr;
3076 let ssock, _ = Unix.accept
sock in
3079 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
3080 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
3084 at_exit
(fun () -> Unix.shutdown
ssock Unix.SHUTDOWN_ALL
);
3088 let () = Glut.displayFunc
display in
3089 let () = Glut.reshapeFunc
reshape in
3090 let () = Glut.keyboardFunc
keyboard in
3091 let () = Glut.specialFunc
special in
3092 let () = Glut.idleFunc
(Some
idle) in
3093 let () = Glut.mouseFunc
mouse in
3094 let () = Glut.motionFunc
motion in
3095 let () = Glut.passiveMotionFunc
pmotion in
3097 init
ssock (conf.angle
, conf.proportional
, conf.texcount
, conf.sliceheight
);
3098 state.csock <- csock;
3099 state.ssock <- ssock;
3100 state.text <- "Opening " ^
state.path;
3101 writeopen state.path state.password
;
3105 let rec handlelablglutbug () =
3108 with Glut.BadEnum
"key in special_of_int" ->
3109 showtext '
!'
" LablGlut bug: special key not recognized";
3110 handlelablglutbug ()
3112 handlelablglutbug ();