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
218 { pat
: string circbuf
219 ; pag
: string circbuf
220 ; nav
: anchor circbuf
234 ; autoscrollstep
= 24
240 ; presentation
= false
245 ; proportional
= true
246 ; memlimit
= 32*1024*1024
253 let conf = { defconf with angle
= defconf.angle
};;
264 ; pagemap
= Hashtbl.create
10
265 ; pagecache
= cbnew 100 ""
276 ; outlines
= Olist
[]
282 { nav
= cbnew 100 (0, 0.0)
298 Printf.kprintf prerr_endline fmt
300 Printf.kprintf ignore fmt
304 let len = String.length s
in
306 let b = Buffer.create
n in
307 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
308 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
309 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
310 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
311 Buffer.add_string
b s
;
312 let s'
= Buffer.contents
b in
313 let n'
= Unix.write fd
s'
0 n in
314 if n'
!= n then failwith
"write failed";
319 let n = Unix.read fd
s 0 4 in
320 if n != 4 then failwith
"incomplete read(len)";
322 lor (Char.code
s.[0] lsl 24)
323 lor (Char.code
s.[1] lsl 16)
324 lor (Char.code
s.[2] lsl 8)
325 lor (Char.code
s.[3] lsl 0)
327 let s = String.create
len in
328 let n = Unix.read fd
s 0 len in
329 if n != len then failwith
"incomplete read(data)";
334 let b = Buffer.create
10 in
335 Buffer.add_string
b s;
336 let rec combine = function
339 Buffer.add_char
b ' '
;
342 | `
b b -> if b then "1" else "0"
344 | `i i
-> string_of_int i
345 | `f f
-> string_of_float f
346 | `I f
-> string_of_int
(truncate f
)
348 Buffer.add_string
b s;
355 let cmd = Buffer.contents
(makecmd s l
) in
356 writecmd state.csock
cmd;
362 let d = conf.winh
- h
in
369 let rec f pn ph pi fh l
=
371 | (n, _
, h
, _
) :: rest
->
372 let ips = calcips h
in
377 if isbirdseye state.mode
&& pn
= 0
382 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
387 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
391 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
394 let fh = f 0 0 0 0 state.pdims
in
398 let getpageyh pageno
=
399 let rec f pn ph pi y l
=
401 | (n, _
, h
, _
) :: rest
->
402 let ips = calcips h
in
405 let h = if n = pageno
then h else ph
in
406 if conf.presentation
&& n = pageno
408 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
410 y
+ (pageno
- pn
) * (ph
+ pi
), h
412 let y = y + (if conf.presentation
then pi
else 0) in
413 let y = y + (n - pn
) * (ph
+ pi
) in
417 y + (pageno
- pn
) * (ph
+ pi
), ph
419 f 0 0 0 0 state.pdims
422 let getpagey pageno
= fst
(getpageyh pageno
);;
425 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~cacheleft ~accu
=
426 let ((w
, h, ips, x
) as curr
), rest
, pdimno
, yinc
=
428 | (pageno'
, w
, h, x
) :: rest
when pageno'
= pageno
->
429 let ips = calcips h in
431 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
435 (w
, h, ips, x
), rest
, pdimno
+ 1, yinc
437 prev
, pdims
, pdimno
, 0
439 let dy = dy + yinc in
440 let py = py + yinc in
441 if pageno
= state.pagecount
|| cacheleft
= 0 || dy >= sh
446 if py + h <= vy - yinc
448 let py = py + h + ips in
449 let dy = max
0 (py - y) in
459 let pagey = vy - py in
460 let pagevh = h - pagey in
461 let pagevh = min
(sh
- dy) pagevh in
462 let off = if yinc > 0 then py - vy else 0 in
463 let py = py + h + ips in
469 ; pagedispy
= dy + off
470 ; pagey = pagey + off
471 ; pagevh = pagevh - off
475 let accu = e :: accu in
482 ~cacheleft
:(cacheleft
-1)
485 if state.invalidated
= 0
495 ~cacheleft
:(cbcap state.pagecache
)
505 let y = state.y + incr
in
507 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
511 let getopaque pageno
=
512 try Some
(Hashtbl.find
state.pagemap
513 (pageno
, state.w
, conf.angle
, conf.proportional
, state.gen
))
514 with Not_found
-> None
517 let cache pageno opaque
=
518 Hashtbl.replace
state.pagemap
519 (pageno
, state.w
, conf.angle
, conf.proportional
, state.gen
) opaque
522 let validopaque opaque
= String.length opaque
> 0;;
525 match getopaque l
.pageno
with
526 | None
when not
state.rendering
->
527 state.rendering
<- true;
528 cache l
.pageno
("", -1);
529 wcmd "render" [`i
(l
.pageno
+ 1)
536 let loadlayout layout =
537 let rec f all
= function
539 begin match getopaque l
.pageno
with
540 | None
-> render l
; f false ls
541 | Some
(opaque
, _
) -> f (all
&& validopaque opaque
) ls
545 f (layout <> []) layout;
548 let findpageforopaque opaque
=
550 (fun k
(v
, s) a
-> if v
= opaque
then Some
(k
, s) else a
)
554 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
560 let memleft = conf.memlimit
- state.memused
in
563 let opaque = cbpeek state.pagecache
in
564 match findpageforopaque opaque with
565 | Some
((n, _
, _
, _
, _
), size
) ->
566 memleft + size
>= 0 && not
(pagevisible state.layout n)
573 let presentation = conf.presentation in
574 let interpagespace = conf.interpagespace in
575 let maxy = state.maxy in
576 conf.presentation <- false;
577 conf.interpagespace <- 0;
578 state.maxy <- calcheight ();
580 match state.layout with
582 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
584 let y = if y < conf.winh
then 0 else y - conf.winh
in
585 let pages = layout y (conf.winh
*3) in
586 List.iter
render pages;
587 conf.presentation <- presentation;
588 conf.interpagespace <- interpagespace;
594 let y = min
state.maxy y in
595 let pages = layout y conf.winh
in
596 let ready = loadlayout pages in
602 state.layout <- pages;
603 state.throttle
<- None
;
604 Glut.postRedisplay
();
607 state.throttle
<- Some
pages;
612 state.layout <- pages;
613 state.throttle
<- None
;
614 Glut.postRedisplay
();
616 begin match state.mode
with
617 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
618 if not
(pagevisible pages pageno
)
620 match state.layout with
623 state.mode
<- Birdseye
(conf, leftx
, l
.pageno
, hooverpageno
, anchor
)
630 let gotoy_and_clear_text y =
632 if not
conf.verbose
then state.text
<- "";
635 let emptyanchor = (0, 0.0);;
638 match state.layout with
640 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
643 let getanchory (n, top
) =
644 let y, h = getpageyh n in
645 y + (truncate
(top
*. float h));
648 let gotoanchor anchor
=
649 gotoy (getanchory anchor
);
653 cbput state.hists
.nav
(getanchor ());
657 let anchor = cbgetc state.hists
.nav ~
-1 in
662 let y, h = getpageyh n in
663 gotoy_and_clear_text (y + (truncate
(top
*. float h)));
666 let gotopage1 n top
=
667 let y = getpagey n in
668 gotoy_and_clear_text (y + top
);
676 state.invalidated
<- state.invalidated
+ 1;
680 let c = c *. state.colorscale
in
685 state.maxy <- calcheight ();
686 match state.mode
with
687 | Birdseye
(_
, _
, pageno
, _
, _
) ->
688 let y, h = getpageyh pageno
in
689 let top = (conf.winh
- h) / 2 in
690 gotoy (max
0 (y - top))
691 | _
-> gotoanchor state.anchor
695 GlMat.mode `projection
;
696 GlMat.load_identity
();
697 GlMat.rotate ~x
:1.0 ~angle
:180.0 ();
698 GlMat.translate ~x
:~
-.1.0 ~
y:~
-.1.0 ();
699 GlMat.scale3
(2.0 /. float state.w
, 2.0 /. float conf.winh
, 1.0);
702 GlMat.translate ~x
:(float state.x
) ();
707 GlMat.mode `projection
;
708 GlMat.load_identity
();
709 GlMat.rotate ~x
:1.0 ~angle
:180.0 ();
710 GlMat.translate ~x
:~
-.1.0 ~
y:~
-.1.0 ();
711 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
715 if state.invalidated
= 0
716 then state.anchor <- getanchor ();
719 let w = truncate
(float w *. conf.zoom
) - conf.scrollw
in
723 GlMat.mode `modelview
;
724 GlMat.load_identity
();
725 GlClear.color
(scalecolor 1.0);
726 GlClear.clear
[`color
];
729 wcmd "geometry" [`i
w; `i
h];
733 GlDraw.color
(0.0, 0.0, 0.0);
735 (0.0, float (conf.winh
- 18))
736 (float (conf.winw
- conf.scrollw
- 1), float conf.winh
)
738 let font = Glut.BITMAP_8_BY_13
in
739 GlDraw.color
(1.0, 1.0, 1.0);
740 GlPix.raster_pos ~x
:0.0 ~
y:(float (conf.winh
- 5)) ();
741 Glut.bitmapCharacter ~
font ~
c:(Char.code
c);
742 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c)) s;
746 let len = String.length
state.text
in
747 match state.mode
with
748 | Textentry
((c, text
, _
, _
, _
), _
) ->
752 text ^
" [" ^
state.text ^
"]"
759 if len > 0 then showtext ' '
state.text
763 state.text
<- Printf.sprintf
"%c%s" c s;
764 Glut.postRedisplay
();
773 state.rects
<- state.rects1
;
774 Glut.postRedisplay
()
777 let n = Scanf.sscanf
cmd "C %u" (fun n -> n) in
778 state.pagecount
<- n;
779 state.invalidated
<- state.invalidated
- 1;
780 if state.invalidated
= 0
784 let s = Scanf.sscanf
cmd "t %n"
785 (fun n -> String.sub
cmd n (String.length
cmd - n))
787 Glut.setWindowTitle
s
790 let s = Scanf.sscanf
cmd "T %n"
791 (fun n -> String.sub
cmd n (String.length
cmd - n))
793 if istextentry state.mode
800 Glut.postRedisplay
();
806 let s = Scanf.sscanf
cmd "V %n"
807 (fun n -> String.sub
cmd n (String.length
cmd - n))
813 let pageno, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
814 Scanf.sscanf
cmd "F %u %d %f %f %f %f %f %f %f %f"
815 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
816 (p
, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
818 let y = (getpagey pageno) + truncate y0
in
821 state.rects1
<- [pageno, c, (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
)]
824 let pageno, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
825 Scanf.sscanf
cmd "R %u %d %f %f %f %f %f %f %f %f"
826 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
827 (p
, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
830 (pageno, c, (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) :: state.rects1
833 let n, w, h, r
, l
, s, p
=
834 Scanf.sscanf
cmd "r %u %u %u %u %d %u %s"
835 (fun n w h r l
s p
->
836 (n-1, w, h, r
, l
!= 0, s, p
))
839 Hashtbl.replace
state.pagemap
(n, w, r
, l
, state.gen
) (p
, s);
840 state.memused
<- state.memused
+ s;
843 match state.throttle
with
844 | None
-> state.layout
845 | Some
layout -> layout
849 if (state.memused
<= conf.memlimit
) || cbempty state.pagecache
852 let evictedopaque = cbpeek state.pagecache
in
853 match findpageforopaque evictedopaque with
854 | None
-> failwith
"bug in gc"
855 | Some
((evictedn
, _
, _
, _
, gen
) as k
, evictedsize
) ->
856 if state.gen
!= gen
|| not
(pagevisible layout evictedn
)
858 wcmd "free" [`
s evictedopaque];
859 state.memused
<- state.memused
- evictedsize
;
860 Hashtbl.remove
state.pagemap k
;
861 cbdecr state.pagecache
;
868 cbput state.pagecache p
;
869 state.rendering
<- false;
871 begin match state.throttle
with
873 if pagevisible state.layout n
876 let allvisible = loadlayout state.layout in
877 if allvisible then preload ();
884 let y = getpagey l
.pageno + l
.pagey in
889 let (n, w, h, x
) as pdim
=
890 Scanf.sscanf
cmd "l %u %u %u %u" (fun n w h x
-> n, w, h, x
)
892 state.pdims
<- pdim
:: state.pdims
895 let (l
, n, t
, h, pos
) =
896 Scanf.sscanf
cmd "o %u %u %d %u %n" (fun l
n t
h pos
-> l
, n, t
, h, pos
)
898 let s = String.sub
cmd pos
(String.length
cmd - pos
) in
900 let l = String.length
s in
901 let b = Buffer.create
(String.length
s) in
908 | '
\xa0'
when pc2 -> Buffer.add_char
b ' '
; false
911 let c = if Char.code
c land 0x80 = 0 then c else '?'
in
920 let outline = (s, l, n, float t
/. float h) in
922 match state.outlines with
923 | Olist
outlines -> Olist
(outline :: outlines)
924 | Oarray _
-> Olist
[outline]
925 | Onarrow _
-> Olist
[outline]
927 state.outlines <- outlines
930 dolog "unknown cmd `%S'" cmd
933 let now = Unix.gettimeofday
;;
937 let r, _
, _
= Unix.select
[state.csock
] [] [] delay
in
940 if state.ascrollstep
> 0
942 let y = state.y + state.ascrollstep
in
943 let y = if y >= state.maxy then 0 else y in
949 let cmd = readcmd state.csock
in
958 let action = function
959 | HCprev
-> cbget cb ~
-1
960 | HCnext
-> cbget cb
1
961 | HCfirst
-> cbget cb ~
-(cb
.rc)
962 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
963 and cancel
() = cb
.rc <- rc
967 let search pattern forward
=
968 if String.length pattern
> 0
971 match state.layout with
974 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
977 let b = makecmd "search"
978 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
980 Buffer.add_char
b '
,'
;
981 Buffer.add_string
b pattern
;
982 Buffer.add_char
b '
\000'
;
985 writecmd state.csock
cmd;
988 let intentry text key
=
989 let c = Char.unsafe_chr key
in
992 let s = "x" in s.[0] <- c;
993 let text = text ^
s in
997 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
1002 let b = Buffer.create
(String.length
s + 1) in
1003 Buffer.add_string
b s;
1004 Buffer.add_char
b c;
1008 let textentry text key
=
1009 let c = Char.unsafe_chr key
in
1011 | _
when key
>= 32 && key
< 127 ->
1012 let text = addchar text c in
1016 dolog "unhandled key %d char `%c'" key
(Char.unsafe_chr key
);
1020 let reinit angle proportional
=
1021 conf.angle
<- angle
;
1022 conf.proportional
<- proportional
;
1024 wcmd "reinit" [`i angle
; `
b proportional
];
1028 let zoom = max
0.01 (min
2.2 zoom) in
1029 if zoom <> conf.zoom
1034 reshape conf.winw
conf.winh
;
1035 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
1039 let enterbirdseye () =
1040 let zoom = float conf.thumbw
/. float conf.winw
in
1041 let birdseyepageno =
1042 let rec fold = function
1044 | l :: _
when l.pagey = 0 -> l.pageno
1045 | _
:: rest
-> fold rest
1049 state.mode
<- Birdseye
(
1050 { conf with zoom = conf.zoom }, state.x
, birdseyepageno, -1, getanchor ()
1053 conf.presentation <- false;
1054 conf.interpagespace <- 10;
1055 conf.hlinks
<- false;
1057 state.mstate
<- Mnone
;
1058 conf.showall
<- false;
1059 Glut.setCursor
Glut.CURSOR_INHERIT
;
1062 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1067 reshape conf.winw
conf.winh
;
1070 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
1072 conf.zoom <- c.zoom;
1073 conf.presentation <- c.presentation;
1074 conf.interpagespace <- c.interpagespace;
1075 conf.showall
<- c.showall
;
1076 conf.hlinks
<- c.hlinks
;
1080 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1083 reshape conf.winw
conf.winh
;
1084 state.anchor <- if goback
then anchor else (pageno, 0.0);
1087 let togglebirdseye () =
1088 match state.mode
with
1089 | Birdseye vals
-> leavebirdseye vals
true
1090 | View
| Outline _
-> enterbirdseye ()
1094 let optentry text key
=
1095 let btos b = if b then "on" else "off" in
1096 let c = Char.unsafe_chr key
in
1100 try conf.scrollstep
<- int_of_string
s with exc
->
1101 state.text <- Printf.sprintf
"bad integer `%s': %s"
1102 s (Printexc.to_string exc
)
1104 TEswitch
('#'
, "", None
, intentry, ondone)
1109 conf.autoscrollstep
<- int_of_string
s;
1110 if state.ascrollstep
> 0
1111 then state.ascrollstep
<- conf.autoscrollstep
;
1113 state.text <- Printf.sprintf
"bad integer `%s': %s"
1114 s (Printexc.to_string exc
)
1116 TEswitch
('
*'
, "", None
, intentry, ondone)
1121 let zoom = float (int_of_string
s) /. 100.0 in
1124 state.text <- Printf.sprintf
"bad integer `%s': %s"
1125 s (Printexc.to_string exc
)
1127 TEswitch
('
@'
, "", None
, intentry, ondone)
1132 conf.thumbw
<- max
2 (min
1920 (int_of_string
s));
1134 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
1135 begin match state.mode
with
1136 | Textentry
(_
, Birdseye beye
) ->
1137 leavebirdseye beye
false;
1142 state.text <- Printf.sprintf
"bad integer `%s': %s"
1143 s (Printexc.to_string exc
)
1145 TEswitch
('$'
, "", None
, intentry, ondone)
1150 Some
(int_of_string
s)
1152 state.text <- Printf.sprintf
"bad integer `%s': %s"
1153 s (Printexc.to_string exc
);
1156 | Some angle
-> reinit angle
conf.proportional
1159 TEswitch
('^'
, "", None
, intentry, ondone)
1162 conf.icase
<- not
conf.icase
;
1163 TEdone
("case insensitive search " ^
(btos conf.icase
))
1166 conf.preload <- not
conf.preload;
1168 TEdone
("preload " ^
(btos conf.preload))
1171 conf.verbose
<- not
conf.verbose
;
1172 TEdone
("verbose " ^
(btos conf.verbose
))
1175 conf.maxhfit
<- not
conf.maxhfit
;
1176 state.maxy <- state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
1177 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
1180 conf.crophack
<- not
conf.crophack
;
1181 TEdone
("crophack " ^
btos conf.crophack
)
1184 conf.showall
<- not
conf.showall
;
1185 TEdone
("showall " ^
btos conf.showall
)
1188 conf.underinfo
<- not
conf.underinfo
;
1189 TEdone
("underinfo " ^
btos conf.underinfo
)
1192 conf.savebmarks
<- not
conf.savebmarks
;
1193 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
1199 match state.layout with
1204 conf.interpagespace <- int_of_string
s;
1205 state.maxy <- calcheight ();
1206 let y = getpagey pageno in
1209 state.text <- Printf.sprintf
"bad integer `%s': %s"
1210 s (Printexc.to_string exc
)
1212 TEswitch
('
%'
, "", None
, intentry, ondone)
1215 reinit conf.angle
(not
conf.proportional
);
1216 TEdone
("proprortional display " ^
btos conf.proportional
)
1219 state.text <- Printf.sprintf
"bad option %d `%c'" key
c;
1223 let maxoutlinerows () = (conf.winh
- 31) / 16;;
1225 let enterselector allowdel
outlines errmsg msg
=
1226 if Array.length
outlines = 0
1228 showtext ' ' errmsg
;
1232 Glut.setCursor
Glut.CURSOR_INHERIT
;
1234 match state.layout with
1236 | {pageno=pageno} :: rest
-> pageno
1240 if n = Array.length
outlines
1243 let (_
, _
, outlinepageno
, _
) = outlines.(n) in
1244 if outlinepageno
>= pageno then n else loop (n+1)
1248 state.mode
<- Outline
1249 (allowdel
, active, max
0 (active - maxoutlinerows () / 2), outlines, "");
1250 Glut.postRedisplay
();
1254 let enteroutlinemode () =
1256 match state.outlines with
1259 let a = Array.of_list
(List.rev
l) in
1260 state.outlines <- Oarray
a;
1262 | Onarrow
(pat
, a, b) ->
1263 a, "Outline was narrowed to `" ^ pat ^
"' (Ctrl-u to restore)"
1265 enterselector false outlines "Document has no outline" msg
;
1268 let enterbookmarkmode () =
1269 let bookmarks = Array.of_list
state.bookmarks in
1270 enterselector true bookmarks "Document has no bookmarks (yet)" "";
1273 let enterinfomode () =
1274 let btos = function true -> "on" | _
-> "off" in
1275 let pageno, top = getanchor () in
1277 let autoscrollstep =
1278 if state.ascrollstep
> 0
1279 then state.ascrollstep
1280 else conf.autoscrollstep
1282 ("Current parameters")
1283 :: ("version " ^
Help.version
)
1284 :: ("presentation mode " ^
btos conf.presentation)
1285 :: ("case insensitive search " ^
btos conf.icase
)
1286 :: ("preload " ^
btos conf.preload)
1287 :: ("page bias " ^ string_of_int
conf.pagebias
)
1288 :: ("verbose " ^
btos conf.verbose
)
1289 :: ("scroll step " ^ string_of_int
conf.scrollstep
)
1290 :: ("max fit " ^
btos conf.maxhfit
)
1291 :: ("crop hack " ^
btos conf.crophack
)
1292 :: ("autoscroll step " ^ string_of_int
autoscrollstep)
1293 :: ("throttle " ^
btos conf.showall
)
1294 :: ("highlight links " ^
btos conf.hlinks
)
1295 :: ("under info " ^
btos conf.underinfo
)
1296 :: ("veritcal margin " ^ string_of_int
conf.interpagespace)
1297 :: ("zoom " ^
Printf.sprintf
"%-5.1f" (conf.zoom*.100.))
1298 :: ("rotation " ^ string_of_int
conf.angle
)
1299 :: ("persistent bookmarks " ^
btos conf.savebmarks
)
1300 :: ("proportional display " ^
btos conf.proportional
)
1301 :: ("pixmap cache size " ^ string_of_int
conf.memlimit
)
1302 :: ("pixmap cache used " ^ string_of_int
state.memused
)
1303 :: ("thumbnail width " ^ string_of_int
conf.thumbw
)
1304 :: (Printf.sprintf
"window dimensions %dx%d " conf.winw
conf.winh
)
1308 let o = Array.create
(List.length
help) ("", 0, pageno, top) in
1309 let rec iteri i
= function
1312 o.(i
) <- (s, (if i
= 0 then 0 else 1), pageno, top);
1318 enterselector false o "Info not available" "";
1321 let enterhelpmode () =
1322 let pageno, top = getanchor () in
1324 let help = ("Keys for llpp " ^
Help.version
) ::state.help in
1325 let o = Array.create
(List.length
help) ("", 0, pageno, top) in
1326 let rec iteri i
= function
1329 o.(i
) <- (s, (if i
= 0 then 0 else 1), pageno, top);
1335 enterselector false o "Help not available" "";
1338 let quickbookmark ?title
() =
1339 match state.layout with
1345 let sec = Unix.gettimeofday
() in
1346 let tm = Unix.localtime
sec in
1347 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
1351 (tm.Unix.tm_year
+ 1900)
1354 | Some
title -> title
1357 (title, 0, l.pageno, float l.pagey /. float l.pageh
) :: state.bookmarks
1361 state.fullscreen
<- None
;
1362 Glut.reshapeWindow
w h;
1365 let writeopen path password
=
1366 writecmd state.csock
("open " ^ path ^
"\000" ^
state.password ^
"\000");
1369 let opendoc path password
=
1372 state.password
<- password
;
1373 state.gen
<- state.gen
+ 1;
1375 writeopen path password
;
1376 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1377 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1380 let viewkeyboard ~key ~x ~
y =
1382 state.mode
<- Textentry
(te
, state.mode
);
1385 Glut.postRedisplay
()
1387 let c = Char.chr key
in
1393 let y = getnav () in
1394 gotoy_and_clear_text y
1402 Glut.postRedisplay
()
1405 let ondone isforw
s =
1406 cbput state.hists
.pat
s;
1407 state.searchpattern
<- s;
1410 enttext (c, "", Some
(onhist state.hists
.pat
),
1411 textentry, ondone (c ='
/'
))
1413 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
1414 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
1415 setzoom (min
2.2 (conf.zoom +. incr))
1420 try int_of_string
s with exc
->
1421 state.text <- Printf.sprintf
"bad integer `%s': %s"
1422 s (Printexc.to_string exc
);
1428 state.text <- "page bias is now " ^ string_of_int
n;
1431 enttext ('
+'
, "", None
, intentry, ondone)
1433 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
1434 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
1435 setzoom (max
0.01 (conf.zoom -. decr))
1441 enttext ('
-'
, "", None
, optentry, ondone)
1443 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1446 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1447 let zoom = zoomforh
conf.winw
conf.winh
conf.scrollw
in
1451 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1457 try int_of_string
s with exc
->
1458 state.text <- Printf.sprintf
"bad integer `%s': %s"
1459 s (Printexc.to_string exc
);
1465 cbput state.hists
.pag
(string_of_int
n);
1466 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
1469 let pageentry text key
=
1470 match Char.unsafe_chr key
with
1471 | 'g'
-> TEdone
text
1472 | _
-> intentry text key
1474 let text = "x" in text.[0] <- c;
1475 enttext ('
:'
, text, Some
(onhist state.hists
.pag
), pageentry, ondone)
1478 conf.scrollw
<- if conf.scrollw
> 0 then 0 else defconf.scrollw
;
1479 reshape conf.winw
conf.winh
;
1482 conf.hlinks
<- not
conf.hlinks
;
1483 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
1484 Glut.postRedisplay
()
1487 if state.ascrollstep
= 0
1488 then state.ascrollstep
<- conf.autoscrollstep
1490 conf.autoscrollstep <- state.ascrollstep
;
1491 state.ascrollstep
<- 0;
1495 conf.presentation <- not
conf.presentation;
1496 showtext ' '
("presentation mode " ^
1497 if conf.presentation then "on" else "off");
1501 begin match state.fullscreen
with
1503 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
1506 state.fullscreen
<- None
;
1511 gotoy_and_clear_text 0
1514 search state.searchpattern
true
1517 search state.searchpattern
false
1520 begin match state.layout with
1523 gotoy_and_clear_text (getpagey l.pageno)
1527 begin match List.rev
state.layout with
1530 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
1531 gotoy_and_clear_text (getpagey pageno)
1535 begin match state.layout with
1538 let pageno = max
0 (l.pageno-1) in
1539 gotoy_and_clear_text (getpagey pageno)
1544 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
1546 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
1548 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
1552 else (100. *. (float state.y /. float maxy)) in
1555 Printf.sprintf
"Page %d of %d %.2f%%"
1556 (fn+1) state.pagecount
percent
1559 "Pages %d-%d of %d %.2f%%"
1560 (fn+1) (ln
+1) state.pagecount
percent
1565 begin match state.layout with
1568 doreshape (l.pagew
+ conf.scrollw
) l.pageh
;
1569 Glut.postRedisplay
();
1573 enterbookmarkmode ()
1583 match state.layout with
1586 (s, 0, l.pageno, float l.pagey /. float l.pageh
)
1590 enttext ('~'
, "", None
, textentry, ondone)
1594 showtext ' '
"Quick bookmark added";
1597 begin match state.layout with
1599 let rect = getpdimrect
l.pagedimno
in
1603 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
1604 truncate
(1.2 *. (rect.(3) -. rect.(0))))
1606 (truncate
(rect.(1) -. rect.(0)),
1607 truncate
(rect.(3) -. rect.(0)))
1611 doreshape (w + conf.scrollw
) (h + conf.interpagespace)
1613 Glut.postRedisplay
();
1619 reinit (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
1624 (min
(state.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 1.0);
1625 Glut.postRedisplay
()
1627 | 'k'
-> gotoy (clamp (-conf.scrollstep
))
1628 | 'j'
-> gotoy (clamp conf.scrollstep
)
1630 | '
r'
-> opendoc state.path
state.password
1633 vlog "huh? %d %c" key
(Char.chr key
);
1636 let textentrykeyboard ~key ~x ~
y ((c, text, opthist
, onkey
, ondone), mode
) =
1638 state.mode
<- Textentry
(te
, mode
);
1641 Glut.postRedisplay
()
1643 match Char.unsafe_chr key
with
1645 let len = String.length
text in
1649 Glut.postRedisplay
();
1652 let s = String.sub
text 0 (len - 1) in
1653 enttext (c, s, opthist
, onkey
, ondone)
1659 Glut.postRedisplay
()
1662 begin match opthist
with
1664 | Some
(_
, onhistcancel
) -> onhistcancel
()
1667 Glut.postRedisplay
()
1670 begin match onkey
text key
with
1674 Glut.postRedisplay
()
1677 enttext (c, text, opthist
, onkey
, ondone);
1681 Glut.postRedisplay
()
1684 state.mode
<- Textentry
(te
, mode
);
1685 Glut.postRedisplay
()
1689 let birdseyekeyboard ~key ~x ~
y ((_
, _
, pageno, _
, anchor) as beye
) =
1692 leavebirdseye beye
true
1695 let y, h = getpageyh pageno in
1696 let top = (conf.winh
- h) / 2 in
1697 gotoy (max
0 (y - top))
1700 leavebirdseye beye
false
1703 viewkeyboard ~key ~x ~
y
1706 let outlinekeyboard ~key ~x ~
y (allowdel
, active, first
, outlines, qsearch
) =
1707 let narrow outlines pattern
=
1708 let reopt = try Some
(Str.regexp_case_fold pattern
) with _
-> None
in
1712 let rec fold accu n =
1716 let (s, _
, _
, _
) as o = outlines.(n) in
1718 if (try ignore
(Str.search_forward re
s 0); true
1719 with Not_found
-> false)
1725 let matched = fold [] (Array.length
outlines - 1) in
1726 if matched = [] then None
else Some
(Array.of_list
matched)
1728 let search active pattern
incr =
1731 if n = Array.length
outlines || n = -1
1734 let (s, _
, _
, _
) = outlines.(n) in
1736 (try ignore
(Str.search_forward re
s 0); true
1737 with Not_found
-> false)
1739 else loop (n + incr)
1744 let re = Str.regexp_case_fold pattern
in
1750 let firstof active = max
0 (active - maxoutlinerows () / 2) in
1753 if String.length qsearch
= 0
1757 Glut.postRedisplay
();
1761 state.mode
<- Outline
(allowdel
, active, first
, outlines, "");
1762 Glut.postRedisplay
();
1766 let incr = if key
= 18 then -1 else 1 in
1768 match search (active + incr) qsearch
incr with
1770 state.text <- qsearch ^
" [not found]";
1773 state.text <- qsearch
;
1774 active, firstof active
1776 state.mode
<- Outline
(allowdel
, active, first
, outlines, qsearch
);
1777 Glut.postRedisplay
();
1780 let len = String.length qsearch
in
1787 state.mode
<- Outline
(allowdel
, active, first
, outlines, "");
1790 let qsearch = String.sub
qsearch 0 (len - 1) in
1792 match search active qsearch ~
-1 with
1794 state.text <- qsearch ^
" [not found]";
1797 state.text <- qsearch;
1798 active, firstof active
1800 state.mode
<- Outline
(allowdel
, active, first
, outlines, qsearch);
1802 Glut.postRedisplay
()
1805 if active < Array.length
outlines
1807 let (_
, _
, n, t
) = outlines.(active) in
1812 if allowdel
then state.bookmarks <- Array.to_list
outlines;
1814 Glut.postRedisplay
();
1816 | _
when key
>= 32 && key
< 127 ->
1817 let pattern = addchar qsearch (Char.chr key
) in
1819 match search active pattern 1 with
1821 state.text <- pattern ^
" [not found]";
1824 state.text <- pattern;
1825 active, firstof active
1827 state.mode
<- Outline
(allowdel
, active, first
, outlines, pattern);
1828 Glut.postRedisplay
()
1830 | 14 when not allowdel
-> (* ctrl-n *)
1831 if String.length
qsearch > 0
1833 let optoutlines = narrow outlines qsearch in
1834 begin match optoutlines with
1835 | None
-> state.text <- "can't narrow"
1837 state.mode
<- Outline
(allowdel
, 0, 0, outlines, qsearch);
1838 match state.outlines with
1841 state.outlines <- Onarrow
(qsearch, outlines, a)
1842 | Onarrow
(pat
, a, b) ->
1843 state.outlines <- Onarrow
(qsearch, outlines, b)
1846 Glut.postRedisplay
()
1848 | 21 when not allowdel
-> (* ctrl-u *)
1850 match state.outlines with
1853 let a = Array.of_list
(List.rev
l) in
1854 state.outlines <- Oarray
a;
1856 | Onarrow
(pat
, a, b) ->
1857 state.outlines <- Oarray
b;
1861 state.mode
<- Outline
(allowdel
, 0, 0, outline, qsearch);
1862 Glut.postRedisplay
()
1865 state.mode
<- Outline
1866 (allowdel
, active, firstof active, outlines, qsearch);
1867 Glut.postRedisplay
()
1869 | 127 when allowdel
->
1870 let len = Array.length
outlines - 1 in
1874 state.bookmarks <- [];
1877 let bookmarks = Array.init
len
1879 let i = if i >= active then i + 1 else i in
1891 Glut.postRedisplay
()
1893 | _
-> dolog "unknown key %d" key
1896 let keyboard ~key ~x ~
y =
1901 match state.mode
with
1902 | Outline
outline -> outlinekeyboard ~key ~x ~
y outline
1903 | Textentry
textentry -> textentrykeyboard ~key ~x ~
y textentry
1904 | Birdseye birdseye
-> birdseyekeyboard ~key ~x ~
y birdseye
1905 | View
-> viewkeyboard ~key ~x ~
y
1908 let birdseyespecial key x
y (conf, leftx
, pageno, hooverpageno
, anchor) =
1911 let pageno = max
0 (pageno - 1) in
1912 let rec loop = function
1913 | [] -> gotopage1 pageno 0
1914 | l :: _
when l.pageno = pageno ->
1915 if l.pagedispy
>= 0 && l.pagey = 0
1916 then Glut.postRedisplay
()
1917 else gotopage1 pageno 0
1918 | _
:: rest
-> loop rest
1921 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
1924 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
1925 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
1926 let rec loop = function
1928 let y, h = getpageyh pageno in
1929 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
1931 | l :: rest
when l.pageno = pageno ->
1932 if l.pagevh != l.pageh
1933 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
1934 else Glut.postRedisplay
()
1935 | l :: rest
-> loop rest
1939 | Glut.KEY_PAGE_UP
->
1940 begin match state.layout with
1944 state.mode
<- Birdseye
(
1945 conf, leftx
, l.pageno, hooverpageno
, anchor
1947 gotopage1 l.pageno 0;
1950 let layout = layout (state.y-conf.winh
) conf.winh
in
1952 | [] -> gotoy (clamp (-conf.winh
))
1954 state.mode
<- Birdseye
(
1955 conf, leftx
, l.pageno, hooverpageno
, anchor
1957 gotopage1 l.pageno 0
1960 | [] -> gotoy (clamp (-conf.winh
))
1963 | Glut.KEY_PAGE_DOWN
->
1964 begin match List.rev
state.layout with
1966 let layout = layout (state.y + conf.winh
) conf.winh
in
1967 begin match layout with
1969 let incr = l.pageh
- l.pagevh in
1974 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
1976 Glut.postRedisplay
();
1978 else gotoy (clamp (incr + conf.interpagespace*2));
1982 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
1983 gotopage1 l.pageno 0;
1986 | [] -> gotoy (clamp conf.winh
)
1990 state.mode
<- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
1994 let pageno = state.pagecount
- 1 in
1995 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
1996 if not
(pagevisible state.layout pageno)
1999 match List.rev
state.pdims
with
2001 | (_
, _
, h, _
) :: _
-> h
2003 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
2004 else Glut.postRedisplay
();
2008 let setautoscrollspeed goingdown
=
2009 let incr = max
1 (state.ascrollstep
/ 2) in
2010 let astep = max
1 (state.ascrollstep
+ (if goingdown
then incr else -incr)) in
2011 state.ascrollstep
<- astep;
2014 let special ~key ~x ~
y =
2015 match state.mode
with
2016 | View
| (Birdseye _
) when key
= Glut.KEY_F9
->
2020 birdseyespecial key x
y vals
2023 if state.ascrollstep
> 0 && (key
= Glut.KEY_DOWN
|| key
= Glut.KEY_UP
)
2024 then setautoscrollspeed (key
= Glut.KEY_DOWN
)
2028 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
2029 | Glut.KEY_UP
-> clamp (-conf.scrollstep
)
2030 | Glut.KEY_DOWN
-> clamp conf.scrollstep
2031 | Glut.KEY_PAGE_UP
->
2032 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2034 match state.layout with
2036 | l :: _
-> state.y - l.pagey
2039 | Glut.KEY_PAGE_DOWN
->
2040 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2042 match List.rev
state.layout with
2044 | l :: _
-> getpagey l.pageno
2047 | Glut.KEY_HOME
-> addnav (); 0
2050 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
2052 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
2053 state.x
<- state.x
- 10;
2055 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
2056 state.x
<- state.x
+ 10;
2061 gotoy_and_clear_text y
2064 ((c, s, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
2067 | Glut.KEY_UP
-> action HCprev
2068 | Glut.KEY_DOWN
-> action HCnext
2069 | Glut.KEY_HOME
-> action HCfirst
2070 | Glut.KEY_END
-> action HClast
2073 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2074 Glut.postRedisplay
()
2078 | Outline
(allowdel
, active, first
, outlines, qsearch) ->
2079 let maxrows = maxoutlinerows () in
2080 let calcfirst first
active =
2083 let rows = active - first
in
2084 if rows > maxrows then active - maxrows else first
2088 let active = active + incr in
2089 let active = max
0 (min
active (Array.length
outlines - 1)) in
2090 let first = calcfirst first active in
2091 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch);
2092 Glut.postRedisplay
()
2094 let updownlevel incr =
2095 let len = Array.length
outlines in
2096 let (_
, curlevel
, _
, _
) = outlines.(active) in
2098 if i = len then i-1 else if i = -1 then 0 else
2099 let (_
, l, _
, _
) = outlines.(i) in
2100 if l != curlevel
then i else flow (i+incr)
2102 let active = flow active in
2103 let first = calcfirst first active in
2104 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch);
2105 Glut.postRedisplay
()
2108 | Glut.KEY_UP
-> navigate ~
-1
2109 | Glut.KEY_DOWN
-> navigate 1
2110 | Glut.KEY_PAGE_UP
-> navigate ~
-maxrows
2111 | Glut.KEY_PAGE_DOWN
-> navigate maxrows
2113 | Glut.KEY_RIGHT
when not allowdel
-> updownlevel 1
2114 | Glut.KEY_LEFT
when not allowdel
-> updownlevel ~
-1
2117 state.mode
<- Outline
(allowdel
, 0, 0, outlines, qsearch);
2118 Glut.postRedisplay
()
2121 let active = Array.length
outlines - 1 in
2122 let first = max
0 (active - maxrows) in
2123 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch);
2124 Glut.postRedisplay
()
2129 let drawplaceholder l =
2130 let margin = state.x
+ (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2132 (float l.pagex
, float l.pagedispy
)
2133 (float (l.pagew
+ l.pagex
), float (l.pagedispy
+ l.pagevh))
2135 let x = float (if margin < 0 then -margin else l.pagex
)
2136 and y = float (l.pagedispy
+ 13) in
2137 let font = Glut.BITMAP_8_BY_13
in
2138 GlDraw.color
(0.0, 0.0, 0.0);
2139 GlPix.raster_pos ~
x ~
y ();
2140 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c))
2141 ("Loading " ^ string_of_int
(l.pageno + 1));
2144 let now () = Unix.gettimeofday
();;
2148 match state.mode
with
2149 | Textentry _
-> scalecolor 0.4
2150 | View
| Outline _
-> scalecolor 1.0
2151 | Birdseye
(_
, _
, pageno, hooverpageno
, _
) ->
2152 if l.pageno = pageno
2155 if l.pageno = hooverpageno
2161 begin match getopaque l.pageno with
2162 | Some
(opaque, _
) when validopaque opaque ->
2164 draw
(l.pagedispy
, l.pagew
, l.pagevh, l.pagey, conf.hlinks
)
2168 vlog "draw %d %f sec" l.pageno d;
2176 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
2177 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2178 let sh = float conf.winh
/. sh in
2179 let sh = max
sh (float conf.scrollh
) in
2182 if state.y = state.maxy
2184 else float y /. float maxy
2186 let position = (float conf.winh
-. sh) *. percent in
2189 if position +. sh > float conf.winh
2190 then float conf.winh
-. sh
2196 let scrollindicator () =
2197 GlDraw.color (0.64 , 0.64, 0.64);
2199 (float (conf.winw
- conf.scrollw
), 0.)
2200 (float conf.winw
, float conf.winh
)
2202 GlDraw.color (0.0, 0.0, 0.0);
2204 let position, sh = scrollph state.y in
2206 (float (conf.winw
- conf.scrollw
), position)
2207 (float conf.winw
, position +. sh)
2211 let showsel margin =
2212 match state.mstate
with
2213 | Mnone
| Mscroll _
| Mpan _
| Mzoom _
->
2216 | Msel
((x0
, y0
), (x1
, y1
)) ->
2217 let rec loop = function
2219 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
2220 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
2222 match getopaque l.pageno with
2223 | Some
(opaque, _
) when validopaque opaque ->
2224 let oy = -l.pagey + l.pagedispy
in
2226 (x0
- margin - state.x, y0
,
2227 x1
- margin - state.x, y1
) oy;
2237 let panx = float state.x in
2239 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
2240 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2242 (fun (pageno, c, (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
2244 if l.pageno = pageno
2246 let d = float (l.pagedispy
- l.pagey) in
2247 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
2248 GlDraw.begins `quads
;
2250 GlDraw.vertex2
(x0
+.panx, y0
+.d);
2251 GlDraw.vertex2
(x1
+.panx, y1
+.d);
2252 GlDraw.vertex2
(x2
+.panx, y2
+.d);
2253 GlDraw.vertex2
(x3
+.panx, y3
+.d);
2263 let showoutline () =
2264 match state.mode
with
2265 | Outline
(allowdel
, active, first, outlines, qsearch) ->
2267 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2268 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2269 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2272 GlDraw.color (1., 1., 1.);
2273 let font = Glut.BITMAP_9_BY_15
in
2274 let draw_string x y s =
2275 GlPix.raster_pos ~
x ~
y ();
2276 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c)) s
2279 if row
= Array.length
outlines || (row
- first) * 16 > conf.winh
2282 let (s, l, _
, _
) = outlines.(row
) in
2283 let y = (row
- first) * 16 in
2288 GlDraw.polygon_mode `both `line
;
2289 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2290 GlDraw.color (1., 1., 1.) ~alpha
:0.9;
2291 GlDraw.rect (0., float (y + 1))
2292 (float (conf.winw
- 1), float (y + 18));
2293 GlDraw.polygon_mode `both `fill
;
2295 GlDraw.color (1., 1., 1.);
2297 draw_string (float x) (float (y + 16)) s;
2307 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2308 GlDraw.viewport
margin 0 state.w conf.winh
;
2310 GlClear.color (scalecolor 0.5);
2311 GlClear.clear
[`
color];
2314 Gl.enable `scissor_test
;
2315 GlMisc.scissor
0 0 (conf.winw
- conf.scrollw
) conf.winh
;
2317 List.iter
drawpage state.layout;
2320 Gl.disable `scissor_test
2324 let x = -.float state.x in
2325 GlMat.translate ~
x ();
2329 GlDraw.viewport
0 0 conf.winw
conf.winh
;
2334 Glut.swapBuffers
();
2338 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2339 let x = x - margin - state.x in
2340 let rec f = function
2342 begin match getopaque l.pageno with
2343 | Some
(opaque, _
) when validopaque opaque ->
2344 let y = y - l.pagedispy
in
2347 let y = l.pagey + y in
2348 let x = x - l.pagex
in
2349 match whatsunder
opaque x y with
2362 let viewmouse button bstate
x y =
2364 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2365 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
2367 match state.mstate
with
2368 | Mzoom
(oldn
, i) ->
2376 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
2378 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
2380 let zoom = conf.zoom +. incr in
2382 state.mstate
<- Mzoom
(n, 0);
2384 state.mstate
<- Mzoom
(n, i+1);
2386 else state.mstate
<- Mzoom
(n, 0)
2388 | _
-> state.mstate
<- Mzoom
(n, 0)
2391 if state.ascrollstep
> 0
2393 setautoscrollspeed (n=4)
2397 then -conf.scrollstep
2398 else conf.scrollstep
2400 let incr = incr * 2 in
2401 let y = clamp incr in
2402 gotoy_and_clear_text y
2405 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
2406 if bstate
= Glut.DOWN
2408 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
2409 state.mstate
<- Mpan
(x, y)
2412 state.mstate
<- Mnone
2414 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollw
->
2415 if bstate
= Glut.DOWN
2417 let position, sh = scrollph state.y in
2418 if y > truncate
position && y < truncate
(position +. sh)
2420 state.mstate
<- Mscroll
2422 let percent = float y /. float conf.winh
in
2423 let desty = truncate
(float (state.maxy - conf.winh
) *. percent) in
2425 state.mstate
<- Mscroll
2427 state.mstate
<- Mnone
2429 | Glut.LEFT_BUTTON
->
2430 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
2431 begin match dest with
2432 | Ulinkgoto
(pageno, top) ->
2436 gotopage1 pageno top;
2442 | Unone
when bstate
= Glut.DOWN
->
2443 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
2444 state.mstate
<- Mpan
(x, y);
2446 | Unone
| Utext _
->
2447 if bstate
= Glut.DOWN
2449 if conf.angle
mod 360 = 0
2451 state.mstate
<- Msel
((x, y), (x, y));
2452 Glut.postRedisplay
()
2456 match state.mstate
with
2459 | Mzoom _
| Mscroll
->
2460 state.mstate
<- Mnone
2463 Glut.setCursor
Glut.CURSOR_INHERIT
;
2464 state.mstate
<- Mnone
2466 | Msel
((x0
, y0
), (x1
, y1
)) ->
2468 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
2469 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
2471 match getopaque l.pageno with
2472 | Some
(opaque, _
) when validopaque opaque ->
2476 List.iter
f state.layout;
2477 copysel
""; (* ugly *)
2478 Glut.setCursor
Glut.CURSOR_INHERIT
;
2479 state.mstate
<- Mnone
;
2486 let birdseyemouse button bstate
x y
2487 (conf, leftx
, pageno, hooverpageno
, anchor) =
2489 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2490 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2491 let rec loop = function
2494 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
2495 && x > margin && x < margin + l.pagew
2497 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
2502 | Glut.OTHER_BUTTON _
-> viewmouse button bstate
x y
2506 let mouse bstate button
x y =
2507 match state.mode
with
2508 | View
-> viewmouse button bstate
x y
2509 | Birdseye beye
-> birdseyemouse button bstate
x y beye
2514 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
2517 match state.mode
with
2520 match state.mstate
with
2521 | Mzoom _
| Mnone
-> ()
2526 state.mstate
<- Mpan
(x, y);
2527 if conf.zoom > 1.0 then state.x <- state.x + dx;
2529 gotoy_and_clear_text y
2532 state.mstate
<- Msel
(a, (x, y));
2533 Glut.postRedisplay
()
2536 let y = min
conf.winh
(max
0 y) in
2537 let percent = float y /. float conf.winh
in
2538 let y = truncate
(float (state.maxy - conf.winh
) *. percent) in
2539 gotoy_and_clear_text y
2543 match state.mode
with
2544 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
2545 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2546 let rec loop = function
2548 if hooverpageno
!= -1
2550 state.mode
<- Birdseye
(conf, leftx
, pageno, -1, anchor);
2551 Glut.postRedisplay
();
2554 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
2555 && x > margin && x < margin + l.pagew
2557 state.mode
<- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
2558 Glut.postRedisplay
();
2566 match state.mstate
with
2568 begin match getunder x y with
2569 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
2571 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
2572 Glut.setCursor
Glut.CURSOR_INFO
2573 | Ulinkgoto
(page
, y) ->
2575 then showtext 'p'
("age: " ^ string_of_int page
);
2576 Glut.setCursor
Glut.CURSOR_INFO
2578 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
2579 Glut.setCursor
Glut.CURSOR_TEXT
2582 | Mpan _
| Msel _
| Mzoom _
| Mscroll
->
2593 match Sys.os_type
with
2594 | "Win32" -> Sys.getenv
"HOMEPATH"
2595 | _
-> Sys.getenv
"HOME"
2598 ("Can not determine home directory location: " ^
2599 Printexc.to_string exn
);
2603 let config_of c attrs
=
2607 | "scroll-bar-width" -> { c with scrollw
= max
0 (int_of_string v
) }
2608 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string v
) }
2609 | "case-insensitive-search" -> { c with icase
= bool_of_string v
}
2610 | "preload" -> { c with preload = bool_of_string v
}
2611 | "page-bias" -> { c with pagebias
= int_of_string v
}
2612 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string v
) }
2613 | "auto-scroll-step" ->
2614 { c with autoscrollstep = max
0 (int_of_string v
) }
2615 | "max-height-fit" -> { c with maxhfit
= bool_of_string v
}
2616 | "crop-hack" -> { c with crophack
= bool_of_string v
}
2617 | "throttle" -> { c with showall
= bool_of_string v
}
2618 | "highlight-links" -> { c with hlinks
= bool_of_string v
}
2619 | "under-cursor-info" -> { c with underinfo
= bool_of_string v
}
2620 | "vertical-margin" ->
2621 { c with interpagespace = max
0 (int_of_string v
) }
2623 let zoom = float_of_string v
/. 100. in
2624 let zoom = max
0.01 (min
2.2 zoom) in
2625 { c with zoom = zoom }
2626 | "presentation" -> { c with presentation = bool_of_string v
}
2627 | "rotation-angle" -> { c with angle
= int_of_string v
}
2628 | "width" -> { c with winw
= max
20 (int_of_string v
) }
2629 | "height" -> { c with winh
= max
20 (int_of_string v
) }
2630 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string v
}
2631 | "proportional-display" -> { c with proportional
= bool_of_string v
}
2632 | "pixmap-cache-size" -> { c with memlimit
= max
2 (int_of_string v
) }
2633 | "tex-count" -> { c with texcount
= max
1 (int_of_string v
) }
2634 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string v
) }
2635 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string v
) }
2638 prerr_endline
("Error processing attribute (`" ^
2639 k ^
"'=`" ^ v ^
"'): " ^
Printexc.to_string exn
);
2642 let rec fold c = function
2645 let c = apply c k v
in
2651 let fromstring f pos
n v
d =
2654 dolog "Error processing attribute (%S=%S) at %d\n%s"
2655 n v pos
(Printexc.to_string exn
)
2660 let bookmark_of attrs
=
2661 let rec fold title page rely
= function
2662 | ("title", v
) :: rest
-> fold v page rely rest
2663 | ("page", v
) :: rest
-> fold title v rely rest
2664 | ("rely", v
) :: rest
-> fold title page v rest
2665 | _
:: rest
-> fold title page rely rest
2666 | [] -> title, page
, rely
2668 fold "invalid" "0" "0" attrs
2672 let rec fold path page rely pan
= function
2673 | ("path", v
) :: rest
-> fold v page rely pan rest
2674 | ("page", v
) :: rest
-> fold path v rely pan rest
2675 | ("rely", v
) :: rest
-> fold path page v pan rest
2676 | ("pan", v
) :: rest
-> fold path page rely v rest
2677 | _
:: rest
-> fold path page rely pan rest
2678 | [] -> path
, page
, rely
, pan
2680 fold "" "0" "0" "0" attrs
2683 let setconf dst src
=
2684 dst
.scrollw
<- src
.scrollw
;
2685 dst
.scrollh
<- src
.scrollh
;
2686 dst
.icase
<- src
.icase
;
2687 dst
.preload <- src
.preload;
2688 dst
.pagebias
<- src
.pagebias
;
2689 dst
.verbose
<- src
.verbose
;
2690 dst
.scrollstep
<- src
.scrollstep
;
2691 dst
.maxhfit
<- src
.maxhfit
;
2692 dst
.crophack
<- src
.crophack
;
2693 dst
.autoscrollstep <- src
.autoscrollstep;
2694 dst
.showall
<- src
.showall
;
2695 dst
.hlinks
<- src
.hlinks
;
2696 dst
.underinfo
<- src
.underinfo
;
2697 dst
.interpagespace <- src
.interpagespace;
2698 dst
.zoom <- src
.zoom;
2699 dst
.presentation <- src
.presentation;
2700 dst
.angle
<- src
.angle
;
2701 dst
.winw
<- src
.winw
;
2702 dst
.winh
<- src
.winh
;
2703 dst
.savebmarks
<- src
.savebmarks
;
2704 dst
.memlimit
<- src
.memlimit
;
2705 dst
.proportional
<- src
.proportional
;
2706 dst
.texcount
<- src
.texcount
;
2707 dst
.sliceheight
<- src
.sliceheight
;
2708 dst
.thumbw
<- src
.thumbw
;
2712 let l = String.length
s in
2713 let b = Buffer.create
l in
2719 let h = Hashtbl.create
10 in
2720 let dc = { defconf with angle
= defconf.angle
} in
2721 let rec toplevel v t spos epos
=
2723 | Vdata
| Vcdata
| Vend
-> v
2724 | Vopen
("llppconfig", attrs
, closed
) ->
2727 else { v
with f = llppconfig
}
2729 error
"unexpected subelement at top level" s spos
2730 | Vclose tag
-> error
"unexpected close at top level" s spos
2732 and llppconfig v t spos epos
=
2734 | Vdata
| Vcdata
| Vend
-> v
2735 | Vopen
("defaults", attrs
, closed
) ->
2736 let c = config_of dc attrs
in
2740 else { v
with f = skip
"defaults" (fun () -> v
) }
2742 | Vopen
("doc", attrs
, closed
) ->
2743 let pathent, spage
, srely
, span
= doc_of attrs
in
2744 let path = unent pathent
2745 and pageno = fromstring int_of_string spos
"page" spage
0
2746 and rely
= fromstring float_of_string spos
"rely" srely
0.0
2747 and pan
= fromstring int_of_string spos
"pan" span
0 in
2748 let c = config_of dc attrs
in
2749 let anchor = (pageno, rely
) in
2751 then (Hashtbl.add
h path (c, [], pan
, anchor); v
)
2752 else { v
with f = doc
path pan
anchor c [] }
2754 | Vopen
(tag
, _
, closed
) ->
2755 error
"unexpected subelement in llppconfig" s spos
2757 | Vclose
"llppconfig" -> { v
with f = toplevel }
2758 | Vclose tag
-> error
"unexpected close in llppconfig" s spos
2760 and doc
path pan
anchor c bookmarks v t spos epos
=
2762 | Vdata
| Vcdata
-> v
2763 | Vend
-> error
"unexpected end of input in doc" s spos
2764 | Vopen
("bookmarks", attrs
, closed
) ->
2765 { v
with f = pbookmarks
path pan
anchor c bookmarks }
2767 | Vopen
(tag
, _
, _
) ->
2768 error
"unexpected subelement in doc" s spos
2771 Hashtbl.add
h path (c, List.rev
bookmarks, pan
, anchor);
2772 { v
with f = llppconfig
}
2774 | Vclose tag
-> error
"unexpected close in doc" s spos
2776 and pbookmarks
path pan
anchor c bookmarks v t spos epos
=
2778 | Vdata
| Vcdata
-> v
2779 | Vend
-> error
"unexpected end of input in bookmarks" s spos
2780 | Vopen
("item", attrs
, closed
) ->
2781 let titleent, spage
, srely
= bookmark_of attrs
in
2782 let page = fromstring int_of_string spos
"page" spage
0
2783 and rely
= fromstring float_of_string spos
"rely" srely
0.0 in
2784 let bookmarks = (unent titleent, 0, page, rely
) :: bookmarks in
2786 then { v
with f = pbookmarks
path pan
anchor c bookmarks }
2789 { v
with f = skip
"item" f }
2792 error
"unexpected subelement in bookmarks" s spos
2794 | Vclose
"bookmarks" ->
2795 { v
with f = doc
path pan
anchor c bookmarks }
2797 | Vclose tag
-> error
"unexpected close in bookmarks" s spos
2799 and skip tag
f v t spos epos
=
2801 | Vdata
| Vcdata
-> v
2803 error
("unexpected end of input in skipped " ^ tag
) s spos
2804 | Vopen
(tag'
, _
, closed
) ->
2808 let f'
() = { v
with f = skip tag
f } in
2809 { v
with f = skip tag'
f'
}
2813 else error
("unexpected close in skipped " ^ tag
) s spos
2816 parse
{ f = toplevel; accu = () } s;
2822 let len = in_channel_length ic
in
2823 let s = String.create
len in
2824 really_input ic
s 0 len;
2827 | Parse_error
(msg
, s, pos
) ->
2828 let subs = subs s pos
in
2829 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
2830 failwith
("parse error: " ^
s)
2833 failwith
("config load error: " ^
Printexc.to_string exn
)
2839 let dir = Filename.concat
home ".config" in
2840 if Sys.is_directory
dir then dir else home
2843 Filename.concat
dir "llpp.conf"
2847 if Sys.file_exists
path
2850 (try Some
(open_in_bin
path)
2853 ("Error opening configuation file `" ^
path ^
"': " ^
2854 Printexc.to_string exn
);
2863 ("Error loading configuation from `" ^
path ^
"': " ^
2864 Printexc.to_string exn
);
2870 f (Hashtbl.create
0, defconf)
2875 let pc, pb
, px
, pa
=
2877 Hashtbl.find
h (Filename.basename
state.path)
2878 with Not_found
-> dc, [], 0, (0, 0.0)
2882 state.bookmarks <- pb
;
2884 cbput state.hists
.nav pa
;
2889 let add_attrs bb always
dc c =
2892 then Printf.bprintf bb
"\n %s='%b'" s a
2895 then Printf.bprintf bb
"\n %s='%d'" s a
2898 then Printf.bprintf bb
"\n %s='%f'" s (a*.100.)
2902 then dc.winw
, dc.winh
2904 match state.fullscreen
with
2906 | None
-> c.winw
, c.winh
2908 let zoom, presentation, interpagespace, showall
=
2910 then dc.zoom, dc.presentation, dc.interpagespace, dc.showall
2912 match state.mode
with
2913 | Birdseye
(bc
, _
, _
, _
, _
) ->
2914 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.showall
2915 | _
-> c.zoom, c.presentation, c.interpagespace, c.showall
2917 oi
"width" w dc.winw
;
2918 oi
"height" h dc.winh
;
2919 oi
"scroll-bar-width" c.scrollw
dc.scrollw
;
2920 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
2921 ob "case-insensitive-search" c.icase
dc.icase
;
2922 ob "preload" c.preload dc.preload;
2923 oi
"page-bias" c.pagebias
dc.pagebias
;
2924 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
2925 oi
"auto-scroll-step" c.autoscrollstep dc.autoscrollstep;
2926 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
2927 ob "crop-hack" c.crophack
dc.crophack
;
2928 ob "throttle" showall
dc.showall
;
2929 ob "highlight-links" c.hlinks
dc.hlinks
;
2930 ob "under-cursor-info" c.underinfo
dc.underinfo
;
2931 oi
"vertical-margin" interpagespace dc.interpagespace;
2932 oz
"zoom" zoom dc.zoom;
2933 ob "presentation" presentation dc.presentation;
2934 oi
"rotation-angle" c.angle
dc.angle
;
2935 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
2936 ob "proportional-display" c.proportional
dc.proportional
;
2937 oi
"pixmap-cache-size" c.memlimit
dc.memlimit
;
2938 oi
"texcount" c.texcount
dc.texcount
;
2939 oi
"slice-height" c.sliceheight
dc.sliceheight
;
2940 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
2944 let bb = Buffer.create
32768 in
2946 Buffer.add_string
bb "<llppconfig>\n<defaults ";
2947 add_attrs bb true dc dc;
2948 Buffer.add_string
bb "/>\n";
2950 let adddoc path pan
anchor c bookmarks =
2951 if bookmarks == [] && c = dc && anchor = emptyanchor
2954 Printf.bprintf
bb "<doc path='%s'"
2955 (enent
path 0 (String.length
path));
2957 if anchor <> emptyanchor
2959 let n, y = anchor in
2960 Printf.bprintf
bb " page='%d'" n;
2961 Printf.bprintf
bb " rely='%f'" y;
2965 then Printf.bprintf
bb " pan='%d'" pan
;
2967 add_attrs bb false dc c;
2969 begin match bookmarks with
2970 | [] -> Buffer.add_string
bb "/>\n"
2972 Buffer.add_string
bb ">\n<bookmarks>\n";
2973 List.iter
(fun (title, _level
, page, rely
) ->
2975 "<item title='%s' page='%d' rely='%f'/>\n"
2976 (enent
title 0 (String.length
title))
2980 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
2986 match state.mode
with
2987 | Birdseye
(_
, pan, _
, _
, _
) -> pan
2990 let basename = Filename.basename state.path in
2991 adddoc basename pan (getanchor ())
2994 if state.ascrollstep
> 0
2995 then state.ascrollstep
2996 else conf.autoscrollstep }
2997 (if conf.savebmarks
then state.bookmarks else []);
2999 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
3001 then adddoc path x y c bookmarks
3003 Buffer.add_string
bb "</llppconfig>";
3006 if Buffer.length
bb > 0
3009 let tmp = path ^
".tmp" in
3010 let oc = open_out_bin
tmp in
3011 Buffer.output_buffer
oc bb;
3013 Sys.rename
tmp path;
3016 ("error while saving configuration: " ^
Printexc.to_string exn
)
3022 ["-p", Arg.String
(fun s -> state.password
<- s) , "password"
3023 ;("-v", Arg.Unit
(fun () -> print_endline
Help.version
; exit
0),
3025 (fun s -> state.path <- s)
3026 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\noptions:")
3028 if String.length
state.path = 0
3029 then (prerr_endline
"filename missing"; exit
1);
3033 let _ = Glut.init
Sys.argv
in
3034 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
3035 let () = Glut.initWindowSize
conf.winw
conf.winh
in
3036 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
3039 if Sys.os_type
= "Unix"
3041 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
3043 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
3044 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
3045 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
3046 Unix.bind
sock addr;
3048 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
3049 Unix.connect
csock addr;
3050 let ssock, _ = Unix.accept
sock in
3053 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
3054 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
3058 at_exit
(fun () -> Unix.shutdown
ssock Unix.SHUTDOWN_ALL
);
3062 let () = Glut.displayFunc
display in
3063 let () = Glut.reshapeFunc
reshape in
3064 let () = Glut.keyboardFunc
keyboard in
3065 let () = Glut.specialFunc
special in
3066 let () = Glut.idleFunc
(Some
idle) in
3067 let () = Glut.mouseFunc
mouse in
3068 let () = Glut.motionFunc
motion in
3069 let () = Glut.passiveMotionFunc
pmotion in
3071 init
ssock (conf.angle
, conf.proportional
, conf.texcount
, conf.sliceheight
);
3072 state.csock <- csock;
3073 state.ssock <- ssock;
3074 state.text <- "Opening " ^
state.path;
3075 writeopen state.path state.password
;
3079 let rec handlelablglutbug () =
3082 with Glut.BadEnum
"key in special_of_int" ->
3083 showtext '
!'
" LablGlut bug: special key not recognized";
3084 handlelablglutbug ()
3086 handlelablglutbug ();