6 external init
: Unix.file_descr
-> initparams
-> unit = "ml_init";;
7 external seltext
: opaque
-> (int * int * int * int) -> unit = "ml_seltext";;
8 external hassel
: opaque
-> bool = "ml_hassel";;
9 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
10 external whatsunder
: opaque
-> int -> int -> under
= "ml_whatsunder";;
11 external markunder
: opaque
-> int -> int -> mark
-> bool = "ml_markunder";;
12 external clearmark
: opaque
-> unit = "ml_clearmark";;
13 external zoomforh
: int -> int -> int -> int -> float = "ml_zoom_for_height";;
14 external getmaxw
: unit -> float = "ml_getmaxw";;
15 external postprocess
:
16 opaque
-> int -> int -> int -> (int * string * int) -> int
18 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
19 external setaalevel
: int -> unit = "ml_setaalevel";;
20 external realloctexts
: int -> bool = "ml_realloctexts";;
21 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
22 external getlink
: opaque
-> int -> under
= "ml_getlink";;
23 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
24 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
25 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links";;
26 external getpbo
: width
-> height
-> colorspace
-> opaque
= "ml_getpbo";;
27 external freepbo
: opaque
-> unit = "ml_freepbo";;
28 external unmappbo
: opaque
-> unit = "ml_unmappbo";;
29 external bousable
: unit -> bool = "ml_bo_usable";;
31 opaque
-> int -> int -> (int * int) option = "ml_unproject";;
33 opaque
-> int -> int -> float -> float -> (float * float) = "ml_project";;
35 tileparams
-> opaque
-> unit = "ml_drawtile";;
36 external rectofblock
:
37 opaque
-> int -> int -> float array
option = "ml_rectofblock";;
38 external begintiles
: unit -> unit = "ml_begintiles";;
39 external endtiles
: unit -> unit = "ml_endtiles";;
40 external addannot
: opaque
-> int -> int -> string -> unit = "ml_addannot";;
41 external modannot
: opaque
-> slinkindex
-> string -> unit = "ml_modannot";;
42 external delannot
: opaque
-> slinkindex
-> unit = "ml_delannot";;
43 external hasunsavedchanges
: unit -> bool = "ml_hasunsavedchanges";;
44 external savedoc
: string -> unit = "ml_savedoc";;
45 external getannotcontents
:
46 opaque
-> slinkindex
-> string = "ml_getannotcontents";;
48 opaque
-> int -> int -> float array
-> unit = "ml_drawprect";;
49 external wcmd
: Unix.file_descr
-> bytes
-> int -> unit = "ml_wcmd";;
50 external rcmd
: Unix.file_descr
-> string = "ml_rcmd";;
51 external uritolocation
:
52 string -> (pageno
* float * float) = "ml_uritolocation";;
53 external isexternallink
: string -> bool = "ml_isexternallink";;
55 (* copysel _will_ close the supplied descriptor *)
56 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
58 let selfexec = ref E.s
;;
59 let ignoredoctitlte = ref false;;
60 let opengl_has_pbo = ref false;;
61 let layouth = ref ~
-1;;
63 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
69 }|} x0 y0 x1 y1 x2 y2 x3 y3
;
72 let pgscale h
= truncate
(float h
*. conf
.pgscale);;
75 if state
.uioh#alwaysscrolly
|| ((conf
.scrollb
land scrollbhv
!= 0)
76 && (state
.w
> state
.winw
))
83 fstate
.wwidth
<- measurestr fstate
.fontsize
"w";
84 fstate
.maxrows
<- (state
.winh
- fstate
.fontsize
- 1) / (fstate
.fontsize
+ 1);
90 else Printf.kprintf ignore fmt
94 if emptystr conf
.pathlauncher
95 then dolog
"%s" state
.path
98 Str.global_replace
Utils.Re.percent state
.path conf
.pathlauncher
in
99 match spawn
command [] with
102 dolog
"failed to execute `%s': %s" command @@ exntos exn
106 let getopaque pageno
=
107 try Some
(Hashtbl.find state
.pagemap
(pageno
, state
.gen
))
108 with Not_found
-> None
111 let pagetranslatepoint l x y
=
112 let dy = y
- l
.pagedispy
in
113 let y = dy + l
.pagey
in
114 let dx = x
- l
.pagedispx
in
115 let x = dx + l
.pagex
in
119 let onppundermouse g
x y d
=
122 begin match getopaque l
.pageno
with
124 let x0 = l
.pagedispx
in
125 let x1 = x0 + l
.pagevw
in
126 let y0 = l
.pagedispy
in
127 let y1 = y0 + l
.pagevh
in
128 if y >= y0 && y <= y1 && x >= x0 && x <= x1
130 let px, py
= pagetranslatepoint l
x y in
131 match g opaque l
px py
with
143 let g opaque l
px py
=
146 match rectofblock opaque
px py
with
147 | Some
[|x0;x1;y0;y1|] ->
148 let rect = (x0, y0, x1, y0, x1, y1, x0, y1) in
149 let color = (0.0, 0.0, 1.0 /. (l
.pageno
mod 3 |> float), 0.5) in
150 state
.rects
<- [l
.pageno
, color, rect];
151 postRedisplay
"getunder";
154 let under = whatsunder opaque
px py
in
155 if under = Unone
then None
else Some
under
157 onppundermouse g x y Unone
162 match unproject opaque
x y with
163 | Some
(x, y) -> Some
(Some
(opaque
, l
.pageno
, x, y))
166 onppundermouse g x y None
;
170 state
.text
<- Printf.sprintf
"%c%s" c s
;
171 postRedisplay
"showtext";
174 let impmsg fmt
= Format.ksprintf
(fun s
-> showtext '
!' s
) fmt
;;
176 let pipesel opaque cmd
=
178 then pipef ~closew
:false "pipesel"
181 postRedisplay
"pipesel"
186 let g opaque l
px py
=
187 if markunder opaque
px py conf
.paxmark
190 match getopaque l
.pageno
with
192 | Some opaque
-> pipesel opaque conf
.paxcmd
197 postRedisplay
"paxunder";
198 if conf
.paxmark
= Mark_page
201 match getopaque l
.pageno
with
203 | Some opaque
-> clearmark opaque
) state
.layout
;
204 state
.roam
<- onppundermouse g x y (fun () -> impmsg "whoopsie daisy");
207 let undertext = function
210 | Utext s
-> "font: " ^ s
211 | Uannotation
(opaque
, slinkindex
) ->
212 "annotation: " ^ getannotcontents opaque slinkindex
215 let updateunder x y =
216 match getunder x y with
217 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
219 if conf
.underinfo
then showtext 'u'
("ri: " ^ uri
);
220 Wsi.setcursor
Wsi.CURSOR_INFO
222 if conf
.underinfo
then showtext '
f'
("ont: " ^ s
);
223 Wsi.setcursor
Wsi.CURSOR_TEXT
225 if conf
.underinfo
then showtext 'a'
"nnotation";
226 Wsi.setcursor
Wsi.CURSOR_INFO
229 let showlinktype under =
230 if conf
.underinfo
&& under != Unone
231 then showtext ' '
@@ undertext under
234 let intentry_with_suffix text key
=
236 match [@warning
"-4"] key
with
237 | Keys.Ascii
('
0'
..'
9'
as c
) -> addchar
text c
238 | Keys.Ascii
('k'
| 'm'
| '
g'
| 'K'
| 'M'
| 'G'
as c
) ->
239 addchar
text @@ asciilower c
241 state
.text <- "invalid key";
248 let b = Buffer.create
16 in
251 let b = Buffer.to_bytes
b in
252 wcmd state
.ss
b @@ Bytes.length
b
256 let nogeomcmds cmds
=
258 | s
, [] -> emptystr s
262 let layoutN ((columns
, coverA
, coverB
), b) x y sw sh
=
263 let rec fold accu n
=
264 if n
= Array.length
b
267 let pdimno, dx, vy
, (_
, w
, h
, xoff
) = b.(n
) in
270 || n
= state
.pagecount
- coverB
271 || (n
- coverA
) mod columns
= columns
- 1)
277 let pagey = max
0 (y - vy
) in
278 let pagedispy = if pagey > 0 then 0 else vy
- y in
279 let pagedispx, pagex
=
281 if n
= coverA
- 1 || n
= state
.pagecount
- coverB
282 then x + (sw
- w
) / 2
290 let vw = sw
- pagedispx in
291 let pw = w
- pagex
in
294 let pagevh = min
(h
- pagey) (sh
- pagedispy) in
295 if pagevw > 0 && pagevh > 0
306 ; pagedispx = pagedispx
307 ; pagedispy = pagedispy
319 if Array.length
b = 0
321 else List.rev
(fold [] (page_of_y
y))
324 let layoutS (columns
, b) x y sw sh
=
325 let rec fold accu n
=
326 if n
= Array.length
b
329 let pdimno, px, vy
, (_
, pagew
, pageh
, xoff
) = b.(n
) in
337 let pagey = max
0 (y - vy
) in
338 let pagedispy = if pagey > 0 then 0 else vy
- y in
339 let pagedispx, pagex
=
353 let pagecolw = pagew
/columns
in
356 then pagedispx + ((sw
- pagecolw) / 2)
360 let vw = sw
- pagedispx in
361 let pw = pagew
- pagex
in
364 let pagevw = min
pagevw pagecolw in
365 let pagevh = min
(pageh
- pagey) (sh
- pagedispy) in
366 if pagevw > 0 && pagevh > 0
377 ; pagedispx = pagedispx
378 ; pagedispy = pagedispy
379 ; pagecol
= n
mod columns
393 let layout x y sw sh
=
394 if nogeomcmds state
.geomcmds
396 match conf
.columns
with
397 | Csingle
b -> layoutN ((1, 0, 0), b) x y sw sh
398 | Cmulti c
-> layoutN c
x y sw sh
399 | Csplit s
-> layoutS s
x y sw sh
403 let maxy () = state
.maxy - if conf
.maxhfit
then state
.winh
else 0;;
404 let clamp incr
= bound
(state
.y + incr
) 0 @@ maxy ();;
407 let tilex = l
.pagex
mod conf
.tilew
in
408 let tiley = l
.pagey mod conf
.tileh
in
410 let col = l
.pagex
/ conf
.tilew
in
411 let row = l
.pagey / conf
.tileh
in
413 let rec rowloop row y0 dispy h
=
417 let dh = conf
.tileh
- y0 in
419 let rec colloop col x0 dispx w
=
422 let dw = conf
.tilew
- x0 in
424 f col row dispx dispy
x0 y0 dw dh;
425 colloop (col+1) 0 (dispx
+dw) (w
-dw)
427 colloop col tilex l
.pagedispx l
.pagevw;
428 rowloop (row+1) 0 (dispy
+dh) (h
-dh)
431 if l
.pagevw > 0 && l
.pagevh > 0
432 then rowloop row tiley l
.pagedispy l
.pagevh;
435 let gettileopaque l
col row =
436 let key = l
.pageno
, state
.gen
, conf
.colorspace
,
437 conf
.angle
, l
.pagew
, l
.pageh
, col, row in
438 try Some
(Hashtbl.find state
.tilemap
key)
439 with Not_found
-> None
442 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
443 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
444 Hashtbl.add state
.tilemap
key (opaque
, size
, elapsed
)
447 let drawtiles l
color =
450 let f col row x y tilex tiley w h
=
451 match gettileopaque l
col row with
452 | Some
(opaque
, _
, t
) ->
453 let params = x, y, w
, h
, tilex, tiley in
455 then GlTex.env
(`mode `blend
);
456 drawtile
params opaque
;
458 then GlTex.env
(`mode `modulate
);
462 let s = Printf.sprintf
466 let w = measurestr fstate
.fontsize
s in
467 GlDraw.color (0.0, 0.0, 0.0);
472 (float (y + fstate
.fontsize
+ 2));
474 drawstring fstate
.fontsize
x (y + fstate
.fontsize
- 1) s;
481 let lw = state
.winw
- x in
484 let lh = state
.winh
- y in
488 then GlTex.env
(`mode `blend
);
489 begin match state
.checkerstexid
with
491 Gl.enable `texture_2d
;
492 GlTex.bind_texture ~target
:`texture_2d id
;
496 and y1 = float (y+h
) in
498 let tw = float w /. 16.0
499 and th
= float h
/. 16.0 in
500 let tx0 = float tilex /. 16.0
501 and ty0
= float tiley /. 16.0 in
503 and ty1
= ty0
+. th
in
504 Raw.sets_float
Glutils.vraw ~pos
:0
505 [| x0; y0; x0; y1; x1; y0; x1; y1 |];
506 Raw.sets_float
Glutils.traw ~pos
:0
507 [| tx0; ty0
; tx0; ty1
; tx1; ty0
; tx1; ty1
|];
508 GlArray.vertex `two
Glutils.vraw
;
509 GlArray.tex_coord `two
Glutils.traw
;
510 GlArray.draw_arrays `triangle_strip ~first
:0 ~count
:4;
511 Gl.disable `texture_2d
;
514 GlDraw.color (1.0, 1.0, 1.0);
515 filledrect
(float x) (float y) (float (x+w)) (float (y+h
));
518 then GlTex.env
(`mode `modulate
);
519 if w > 128 && h
> fstate
.fontsize
+ 10
521 let c = if conf
.invert
then 1.0 else 0.0 in
522 GlDraw.color (c, c, c);
525 then (col*conf
.tilew
, row*conf
.tileh
)
528 drawstring2 fstate
.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
537 let pagevisible layout n
= List.exists
(fun l
-> l
.pageno
= n
) layout;;
539 let tilevisible1 l
x y =
541 and ax1
= l
.pagex
+ l
.pagevw
543 and ay1
= l
.pagey + l
.pagevh in
547 let bx1 = min
(bx0 + conf
.tilew
) l
.pagew
548 and by1
= min
(by0
+ conf
.tileh
) l
.pageh
in
550 let rx0 = max
ax0 bx0
551 and ry0
= max ay0 by0
552 and rx1
= min ax1
bx1
553 and ry1
= min ay1 by1
in
555 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
559 let tilevisible layout n
x y =
560 let rec findpageinlayout m
= function
561 | l
:: rest
when l
.pageno
= n
->
562 tilevisible1 l
x y || (
563 match conf
.columns
with
564 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
565 | Csplit _
| Csingle _
| Cmulti _
-> false
567 | _
:: rest
-> findpageinlayout 0 rest
570 findpageinlayout 0 layout;
573 let tileready l
x y =
574 tilevisible1 l
x y &&
575 gettileopaque l
(x/conf
.tilew
) (y/conf
.tileh
) != None
578 let tilepage n p
layout =
579 let rec loop = function
583 let f col row _ _ _ _ _ _
=
584 if state
.currently
= Idle
586 match gettileopaque l
col row with
589 let x = col*conf
.tilew
590 and y = row*conf
.tileh
in
592 let w = l
.pagew
- x in
596 let h = l
.pageh
- y in
601 then getpbo
w h conf
.colorspace
604 wcmd "tile %s %d %d %d %d %s" (~
> p
) x y w h (~
> pbo);
607 l
, p
, conf
.colorspace
, conf
.angle
,
608 state
.gen
, col, row, conf
.tilew
, conf
.tileh
617 if nogeomcmds state
.geomcmds
621 let preloadlayout x y sw sh
=
622 let y = if y < sh
then 0 else y - sh
in
623 let x = min
0 (x + sw
) in
631 if state
.currently
= Idle
635 begin match getopaque l
.pageno
with
637 wcmd "page %d %d" l
.pageno l
.pagedimno
;
638 state
.currently
<- Loading
(l
, state
.gen
);
640 tilepage l
.pageno opaque pages
;
645 if nogeomcmds state
.geomcmds
651 if conf
.preload && state
.currently
= Idle
652 then load (preloadlayout state
.x state
.y state
.winw state
.winh
);
655 let layoutready layout =
656 let rec fold all ls
=
659 let seen = ref false in
660 let allvisible = ref true in
661 let foo col row _ _ _ _ _ _
=
663 allvisible := !allvisible &&
664 begin match gettileopaque l
col row with
670 fold (!seen && !allvisible) rest
673 let alltilesvisible = fold true layout in
678 let y = bound
y 0 state
.maxy in
680 let layout = layout x y state
.winw state
.winh
in
681 postRedisplay
"gotoxy ready";
686 state
.layout <- layout;
687 begin match state
.mode
with
690 | Ltexact
(pageno
, linkno
) ->
691 let rec loop = function
693 state
.lnava
<- Some
(pageno
, linkno
);
694 state
.mode
<- LinkNav
(Ltgendir
0)
695 | l
:: _
when l
.pageno
= pageno
->
696 begin match getopaque pageno
with
697 | None
-> state
.mode
<- LinkNav
(Ltnotready
(pageno
, 0))
699 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
700 if not
(x0 >= l
.pagex
&& x1 <= l
.pagex
+ l
.pagevw
701 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
702 then state
.mode
<- LinkNav
(Ltgendir
0)
704 | _
:: rest
-> loop rest
707 | Ltnotready _
| Ltgendir _
-> ()
709 | Birdseye _
| Textentry _
| View
-> ()
711 begin match state
.mode
with
712 | Birdseye
(conf
, leftx
, pageno
, hooverpageno
, anchor
) ->
713 if not
(pagevisible layout pageno
)
715 match state
.layout with
718 state
.mode
<- Birdseye
(conf
, leftx
, l
.pageno
, hooverpageno
, anchor
)
722 | Ltnotready
(_
, dir
)
725 let rec loop = function
728 match getopaque l
.pageno
with
729 | None
-> Ltnotready
(l
.pageno
, dir
)
734 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
736 if dir
> 0 then LDfirst
else LDlast
742 | Lnotfound
-> loop rest
744 showlinktype (getlink opaque n
);
745 Ltexact
(l
.pageno
, n
)
749 state
.mode
<- LinkNav
linknav
752 | Textentry _
| View
-> ()
757 let mx, my
= state
.mpos
in
762 let conttiling pageno opaque
=
763 tilepage pageno opaque
765 then preloadlayout state
.x state
.y state
.winw state
.winh
770 if not conf
.verbose
then state
.text <- E.s;
774 let getanchory (n
, top
, dtop
) =
775 let y, h = getpageyh n
in
778 let ips = calcips
h in
779 y + truncate
(top
*.float h -. dtop
*.float ips) + ips;
780 else y + truncate
(top
*.float h -. dtop
*.float conf
.interpagespace
)
783 let gotoanchor anchor
= gotoxy state
.x (getanchory anchor
);;
784 let addnav () = getanchor
() |> cbput state
.hists
.nav
;;
785 let addnavnorc () = getanchor
() |> cbput_dont_update_rc state
.hists
.nav
;;
788 let anchor = cbgetc state
.hists
.nav dir
in
793 let y, h = getpageyh n
in
794 let y = y + (truncate
(top
*. float h)) in
798 let gotopage1 n top
=
799 let y = getpagey n
in
805 Glutils.redisplay
:= false;
810 match state
.geomcmds
with
811 | ps
, [] when emptystr ps
->
813 state
.geomcmds
<- s, [];
814 | ps
, [] -> state
.geomcmds
<- ps
, [s, f];
815 | ps
, (s'
, _
) :: rest
when s'
= s -> state
.geomcmds
<- ps
, ((s, f) :: rest
);
816 | ps
, cmds
-> state
.geomcmds
<- ps
, ((s, f) :: cmds
);
820 Hashtbl.iter
(fun _ opaque
-> wcmd "freepage %s" (~
> opaque
)) state
.pagemap
;
821 Hashtbl.clear state
.pagemap
;
825 if not
(Queue.is_empty state
.tilelru
)
827 Queue.iter
(fun (k
, p
, s) ->
828 wcmd "freetile %s" (~
> p
);
829 state
.memused
<- state
.memused
- s;
830 Hashtbl.remove state
.tilemap k
;
832 state
.uioh#infochanged Memused
;
833 Queue.clear state
.tilelru
;
839 let h = truncate
(float h*.conf
.zoom
) in
840 let d = conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0) in
846 let sl = keystostrlist conf
in
848 function | [] -> accu
849 | s :: rest
-> loop ((s, 0, Noaction
) :: accu) rest
850 in Help.makehelp conf
.urilauncher
851 @ (("", 0, Noaction
) :: loop [] sl) |> Array.of_list
854 let opendoc path password
=
856 state
.password
<- password
;
857 state
.gen
<- state
.gen
+ 1;
859 state
.outlines
<- [||];
862 setaalevel conf
.aalevel
;
864 if emptystr state
.origin
868 Wsi.settitle
("llpp " ^ mbtoutf8
(Filename.basename
titlepath));
869 wcmd "open %d %d %s\000%s\000%s\000"
870 (btod conf
.usedoccss
) !layouth
871 path password conf
.css
;
872 invalidate "reqlayout"
874 wcmd "reqlayout %d %d %d %s\000"
875 conf
.angle
(FMTE.to_int conf
.fitmodel
)
876 (stateh state
.winh
) state
.nameddest
882 state
.anchor <- getanchor
();
883 opendoc state
.path state
.password
;
887 let c = c *. conf
.colorscale
in
891 let scalecolor2 (r
, g, b) =
892 (r
*. conf
.colorscale
, g *. conf
.colorscale
, b *. conf
.colorscale
);
895 let docolumns columns
=
898 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
899 let rec loop pageno
pdimno pdim
y ph pdims
=
900 if pageno
= state
.pagecount
903 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
905 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
910 let x = max
0 (((state
.winw
- w) / 2) - xoff
) in
912 y + (if conf
.presentation
913 then (if pageno
= 0 then calcips
h else calcips ph
+ calcips
h)
914 else (if pageno
= 0 then 0 else conf
.interpagespace
))
916 a.(pageno
) <- (pdimno, x, y, pdim
);
917 loop (pageno
+1) pdimno pdim
(y + h) h pdims
919 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 state
.pdims
;
920 conf
.columns
<- Csingle
a;
922 | Cmulti
((columns
, coverA
, coverB
), _
) ->
923 let a = Array.make state
.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
924 let rec loop pageno
pdimno pdim
x y rowh pdims
=
926 if m
= pageno
then () else
927 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
930 let y = y + (rowh
- h) / 2 in
931 a.(m
) <- (pdimno, x, y, pdim
);
935 if pageno
= state
.pagecount
936 then fixrow (((pageno
- 1) / columns
) * columns
)
938 let pdimno, ((_
, w, h, xoff
) as pdim
), pdims
=
940 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
942 | _
-> pdimno, pdim
, pdims
945 if pageno
= coverA
- 1 || pageno
= state
.pagecount
- coverB
947 let x = (state
.winw
- w) / 2 in
949 if conf
.presentation
then calcips
h else conf
.interpagespace
in
953 if (pageno
- coverA
) mod columns
= 0
955 let x = max
0 (state
.winw
- state
.w) / 2 in
959 let ips = calcips
h in
960 y + (if pageno
= 0 then 0 else calcips rowh
+ ips)
962 y + (if pageno
= 0 then 0 else conf
.interpagespace
)
966 else x, y, max rowh
h
970 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
973 if pageno
= columns
&& conf
.presentation
975 let ips = calcips rowh
in
976 for i
= 0 to pred columns
978 let (pdimno, x, y, pdim
) = a.(i
) in
979 a.(i
) <- (pdimno, x, y+ips, pdim
)
985 fixrow (pageno
- columns
);
990 a.(pageno
) <- (pdimno, x, y, pdim
);
991 let x = x + w + xoff
*2 + conf
.interpagespace
in
992 loop (pageno
+1) pdimno pdim
x y rowh' pdims
994 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state
.pdims
;
995 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
998 let a = Array.make
(state
.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
999 let rec loop pageno
pdimno pdim
y pdims
=
1000 if pageno
!= state
.pagecount
1002 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1004 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1005 pdimno+1, pdim
, rest
1006 | _
-> pdimno, pdim
, pdims
1009 let rec loop1 n
x y =
1010 if n
= c then y else (
1011 a.(pageno
*c + n
) <- (pdimno, x, y, pdim
);
1012 loop1 (n
+1) (x+cw) (y + h + conf
.interpagespace
)
1015 let y = loop1 0 0 y in
1016 loop (pageno
+1) pdimno pdim
y pdims
1018 loop 0 ~
-1 (-1,-1,-1,-1) 0 state
.pdims
;
1019 conf
.columns
<- Csplit
(c, a);
1023 docolumns conf
.columns
;
1024 state
.maxy <- calcheight
();
1025 if state
.reprf
== noreprf
1027 match state
.mode
with
1028 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1029 let y, h = getpageyh pageno
in
1030 let top = (state
.winh
- h) / 2 in
1031 gotoxy state
.x (max
0 (y - top))
1032 | Textentry _
| View
| LinkNav _
->
1033 let y = getanchory state
.anchor in
1034 let y = min
y (state
.maxy - state
.winh
) in
1039 state
.reprf
<- noreprf
;
1043 let reshape ?
(firsttime
=false) w h =
1044 GlDraw.viewport ~
x:0 ~
y:0 ~
w ~
h;
1045 if not firsttime
&& nogeomcmds state
.geomcmds
1046 then state
.anchor <- getanchor
();
1049 let w = truncate
(float w *. conf
.zoom
) in
1052 setfontsize fstate
.fontsize
;
1053 GlMat.mode `modelview
;
1054 GlMat.load_identity
();
1056 GlMat.mode `projection
;
1057 GlMat.load_identity
();
1058 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1059 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1060 GlMat.scale3
(2.0 /. float state
.winw
, 2.0 /. float state
.winh
, 1.0);
1065 else float state
.x /. float state
.w
1067 invalidate "geometry"
1071 then state
.x <- truncate
(relx *. float w);
1073 match conf
.columns
with
1075 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf
.interpagespace
) / c
1076 | Csplit
(c, _
) -> w * c
1078 wcmd "geometry %d %d %d" w (stateh h) (FMTE.to_int conf
.fitmodel
)
1083 let len = Queue.length state
.tilelru
in
1084 let layout = lazy (if conf
.preload
1085 then preloadlayout state
.x state
.y state
.winw state
.winh
1086 else state
.layout) in
1088 if state
.memused
> conf
.memlimit
1092 let (k
, p
, s) as lruitem
= Queue.pop state
.tilelru
in
1093 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1094 let (_
, pw, ph
, _
) = getpagedim
n in
1096 && colorspace
= conf
.colorspace
1097 && angle
= conf
.angle
1101 let x = col*conf
.tilew
and y = row*conf
.tileh
in
1102 tilevisible (Lazy.force_val
layout) n x y
1104 then Queue.push lruitem state
.tilelru
1107 wcmd "freetile %s" (~
> p
);
1108 state
.memused
<- state
.memused
- s;
1109 state
.uioh#infochanged Memused
;
1110 Hashtbl.remove state
.tilemap k
;
1118 let onpagerect pageno
f =
1120 match conf
.columns
with
1121 | Cmulti
(_
, b) -> b
1123 | Csplit
(_
, b) -> b
1125 if pageno
>= 0 && pageno
< Array.length
b
1127 let (_
, _
, _
, (_
, w, h, _
)) = b.(pageno
) in
1131 let gotopagexy1 pageno
x y =
1132 let _,w1
,h1
,leftx
= getpagedim pageno
in
1133 let top = y /. (float h1
) in
1134 let left = x /. (float w1
) in
1135 let py, w, h = getpageywh pageno
in
1136 let wh = state
.winh
in
1137 let x = left *. (float w) in
1138 let x = leftx
+ state
.x + truncate
x in
1140 if x < 0 || x >= state
.winw
1144 let pdy = truncate
(top *. float h) in
1145 let y'
= py + pdy in
1146 let dy = y'
- state
.y in
1148 if x != state
.x || not
(dy > 0 && dy < wh)
1150 if conf
.presentation
1152 if abs
(py - y'
) > wh
1159 if state
.x != sx || state
.y != sy
1161 else gotoxy state
.x state
.y;
1164 let gotopagexy pageno
x y =
1165 match state
.mode
with
1166 | Birdseye
_ -> gotopage pageno
0.0
1167 | Textentry
_ | View
| LinkNav
_ -> gotopagexy1 pageno
x y
1170 let getpassword () =
1171 let passcmd = getenvwithdef
"LLPP_ASKPASS" conf
.passcmd in
1176 impmsg "error getting password: %s" s;
1177 dolog
"%s" s) passcmd;
1180 let pgoto opaque pageno
x y =
1181 let pdimno = getpdimno pageno
in
1182 let x, y = project opaque pageno
pdimno x y in
1183 gotopagexy pageno
x y;
1187 (* dolog "%S" cmds; *)
1188 let spl = splitatchar cmds ' '
in
1190 try Scanf.sscanf
s fmt
f
1192 dolog
"error processing '%S': %s" cmds
@@ exntos exn
;
1195 let addoutline outline
=
1196 match state
.currently
with
1197 | Outlining outlines
-> state
.currently
<- Outlining
(outline
:: outlines
)
1198 | Idle
-> state
.currently
<- Outlining
[outline
]
1199 | Loading
_ | Tiling
_ ->
1200 dolog
"invalid outlining state";
1201 logcurrently state
.currently
1206 state
.uioh#infochanged Pdim
;
1208 | "clearrects", "" ->
1209 state
.rects
<- state
.rects1
;
1210 postRedisplay
"clearrects";
1212 | "continue", args
->
1213 let n = scan args
"%u" (fun n -> n) in
1214 state
.pagecount
<- n;
1215 begin match state
.currently
with
1217 state
.currently
<- Idle
;
1218 state
.outlines
<- Array.of_list
(List.rev l
)
1219 | Idle
| Loading
_ | Tiling
_ -> ()
1222 let cur, cmds
= state
.geomcmds
in
1224 then error
"empty geomcmd";
1226 begin match List.rev cmds
with
1228 state
.geomcmds
<- E.s, [];
1232 state
.geomcmds
<- s, List.rev rest
;
1234 postRedisplay
"continue";
1241 then showtext ' ' args
1244 Buffer.add_string state
.errmsgs args
;
1245 state
.newerrmsgs
<- true;
1246 postRedisplay
"error message"
1248 | "progress", args
->
1249 let progress, text =
1252 f, String.sub args pos
(String.length args
- pos
))
1255 state
.progress <- progress;
1256 postRedisplay
"progress"
1258 | "firstmatch", args
->
1259 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1260 scan args
"%u %d %f %f %f %f %f %f %f %f"
1261 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1262 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1264 let y = (getpagey
pageno) + truncate
y0 in
1266 if (state
.x < - truncate
x0) || (state
.x > state
.winw
- truncate
x1)
1267 then state
.winw
/2 - truncate
(x0 /. 2. +. x1 /. 2.)
1272 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1273 state
.rects1
<- [pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
1276 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
1277 scan args
"%u %d %f %f %f %f %f %f %f %f"
1278 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
1279 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
1281 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
1283 (pageno, color, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state
.rects1
1286 let pageopaques, t
= scan args
"%s %f" (fun p t
-> p
, t
) in
1287 let pageopaque = ~
< pageopaques in
1288 begin match state
.currently
with
1289 | Loading
(l
, gen
) ->
1290 vlog "page %d took %f sec" l
.pageno t
;
1291 Hashtbl.replace state
.pagemap
(l
.pageno, gen
) pageopaque;
1292 let preloadedpages =
1294 then preloadlayout state
.x state
.y state
.winw state
.winh
1298 let set = List.fold_left
(fun s l
-> IntSet.add l
.pageno s)
1299 IntSet.empty
preloadedpages
1302 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1303 if not
(IntSet.mem
pageno set)
1305 wcmd "freepage %s" (~
> opaque
);
1311 List.iter
(Hashtbl.remove state
.pagemap
) evictedpages;
1314 state
.currently
<- Idle
;
1317 tilepage l
.pageno pageopaque state
.layout;
1319 load preloadedpages;
1320 let visible = pagevisible state
.layout l
.pageno in
1323 match state
.mode
with
1324 | LinkNav
(Ltnotready
(pageno, dir
)) ->
1325 if pageno = l
.pageno
1330 then LDfirstvisible
(l
.pagex
, l
.pagey, dir
)
1332 if dir
> 0 then LDfirst
else LDlast
1335 findlink
pageopaque ld
1340 showlinktype (getlink
pageopaque n);
1341 state
.mode
<- LinkNav
(Ltexact
(l
.pageno, n))
1343 | LinkNav
(Ltgendir
_)
1344 | LinkNav
(Ltexact
_)
1350 if visible && layoutready state
.layout
1352 postRedisplay
"page";
1356 | Idle
| Tiling
_ | Outlining
_ ->
1357 dolog
"Inconsistent loading state";
1358 logcurrently state
.currently
;
1363 let (x, y, opaques
, size
, t
) =
1364 scan args
"%u %u %s %u %f"
1365 (fun x y p size t
-> (x, y, p
, size
, t
))
1367 let opaque = ~
< opaques
in
1368 begin match state
.currently
with
1369 | Tiling
(l
, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1370 vlog "tile %d [%d,%d] took %f sec" l
.pageno col row t
;
1373 if tilew
!= conf
.tilew
|| tileh
!= conf
.tileh
1375 wcmd "freetile %s" (~
> opaque);
1376 state
.currently
<- Idle
;
1380 puttileopaque l
col row gen cs angle
opaque size t
;
1381 state
.memused
<- state
.memused
+ size
;
1382 state
.uioh#infochanged Memused
;
1384 Queue.push
((l
.pageno, gen
, cs
, angle
, l
.pagew
, l
.pageh
, col, row),
1385 opaque, size
) state
.tilelru
;
1387 state
.currently
<- Idle
;
1389 && conf
.colorspace
= cs
1390 && conf
.angle
= angle
1391 && tilevisible state
.layout l
.pageno x y
1392 then conttiling l
.pageno pageopaque;
1394 preload state
.layout;
1396 && conf
.colorspace
= cs
1397 && conf
.angle
= angle
1398 && tilevisible state
.layout l
.pageno x y
1399 && layoutready state
.layout
1400 then postRedisplay
"tile nothrottle";
1403 | Idle
| Loading
_ | Outlining
_ ->
1404 dolog
"Inconsistent tiling state";
1405 logcurrently state
.currently
;
1410 let (n, w, h, _) as pdim
=
1411 scan args
"%u %u %u %u" (fun n w h x -> n, w, h, x)
1414 match conf
.fitmodel
with
1416 | FitPage
| FitProportional
->
1417 match conf
.columns
with
1418 | Csplit
_ -> (n, w, h, 0)
1419 | Csingle
_ | Cmulti
_ -> pdim
1421 state
.pdims
<- pdim :: state
.pdims
;
1422 state
.uioh#infochanged Pdim
1425 let (l
, n, t
, h, pos
) =
1426 scan args
"%u %u %d %u %n" (fun l
n t
h pos
-> l
, n, t
, h, pos
)
1428 let s = String.sub args pos
(String.length args
- pos
) in
1429 addoutline (s, l
, Oanchor
(n, float t
/. float h, 0.0))
1432 let (l
, len, pos
) = scan args
"%u %u %n" (fun l
len pos
-> l
, len, pos
) in
1433 let s = String.sub args pos
len in
1434 let pos2 = pos
+ len + 1 in
1435 let uri = String.sub args
pos2 (String.length args
- pos2) in
1436 addoutline (s, l
, Ouri
uri)
1439 let (l
, pos
) = scan args
"%u %n" (fun l pos
-> l
, pos
) in
1440 let s = String.sub args pos
(String.length args
- pos
) in
1441 addoutline (s, l
, Onone
)
1444 let (n, l
, t
) = scan args
"%u %d %d" (fun n l t
-> n, l
, t
) in
1445 state
.reprf
<- (fun () -> gotopagexy n (float l
) (float t
))
1448 let c, v
= splitatchar args '
\t'
in
1455 if not
!ignoredoctitlte
1456 then Wsi.settitle v
;
1460 if let len = String.length
c in
1461 len > 6 && ((String.sub
c (len-4) 4) = "date")
1463 if String.length v
>= 7 && v
.[0] = 'D'
&& v
.[1] = '
:'
1465 let b = Buffer.create
10 in
1466 Printf.bprintf
b "%s\t" c;
1469 Buffer.add_substring
b v p l
;
1470 Buffer.add_char
b c;
1471 with exn
-> Buffer.add_string
b @@ exntos exn
1479 Buffer.add_char
b '
['
;
1480 Buffer.add_string
b v
;
1481 Buffer.add_char
b '
]'
;
1488 state
.docinfo
<- (1, s) :: state
.docinfo
1491 state
.docinfo
<- List.rev state
.docinfo
;
1492 state
.uioh#infochanged Docinfo
1496 then Wsi.settitle
"Wrong password";
1497 let password = getpassword () in
1498 if emptystr
password
1499 then error
"document is password protected"
1500 else opendoc state
.path
password
1502 | _ -> error
"unknown cmd `%S'" cmds
1507 let action = function
1508 | HCprev
-> cbget cb ~
-1
1509 | HCnext
-> cbget cb
1
1510 | HCfirst
-> cbget cb ~
-(cb
.rc)
1511 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
1512 and cancel
() = cb
.rc <- rc
1516 let search pattern forward
=
1517 match conf
.columns
with
1518 | Csplit
_ -> impmsg "searching does not work properly in split columns mode"
1519 | Csingle
_ | Cmulti
_ ->
1520 if nonemptystr pattern
1523 match state
.layout with
1525 | l
:: _ -> l
.pageno, (l
.pagey + if forward
then 0 else 0*l
.pagevh)
1527 wcmd "search %d %d %d %d,%s\000"
1528 (btod conf
.icase
) pn py (btod forward
) pattern
;
1531 let intentry text key =
1533 if emptystr
text && key = Keys.Ascii '
-'
1534 then addchar
text '
-'
1536 match [@warning
"-4"] key with
1537 | Keys.Ascii
('
0'
..'
9'
as c) -> addchar
text c
1539 state
.text <- "invalid key";
1549 let l = String.length
s in
1550 let rec loop pos
n =
1554 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
1555 loop (pos
+1) (n*26 + m)
1558 let rec loop n = function
1561 match getopaque l.pageno with
1562 | None
-> loop n rest
1564 let m = getlinkcount
opaque in
1567 let under = getlink
opaque n in
1570 else loop (n-m) rest
1572 loop n state
.layout;
1576 let linknentry text key = match [@warning
"-4"] key with
1578 let text = addchar
text c in
1579 linknact (fun under -> state
.text <- undertext under) text;
1582 state
.text <- Printf.sprintf
"invalid key";
1586 let textentry text key = match [@warning
"-4"] key with
1587 | Keys.Ascii
c -> TEcont
(addchar
text c)
1588 | Keys.Code
c -> TEcont
(text ^ toutf8
c)
1592 let reqlayout angle fitmodel
=
1593 if nogeomcmds state
.geomcmds
1594 then state
.anchor <- getanchor
();
1595 conf
.angle
<- angle
mod 360;
1598 match state
.mode
with
1599 | LinkNav
_ -> state
.mode
<- View
1600 | Birdseye
_ | Textentry
_ | View
-> ()
1602 conf
.fitmodel
<- fitmodel
;
1603 invalidate "reqlayout"
1605 wcmd "reqlayout %d %d %d"
1606 conf
.angle
(FMTE.to_int conf
.fitmodel
) (stateh state
.winh
)
1610 let settrim trimmargins trimfuzz
=
1611 if nogeomcmds state
.geomcmds
1612 then state
.anchor <- getanchor
();
1613 conf
.trimmargins
<- trimmargins
;
1614 conf
.trimfuzz
<- trimfuzz
;
1615 let x0, y0, x1, y1 = trimfuzz
in
1616 invalidate "settrim"
1617 (fun () -> wcmd "settrim %d %d %d %d %d"
1618 (btod conf
.trimmargins
) x0 y0 x1 y1);
1623 let zoom = max
0.0001 zoom in
1624 if zoom <> conf
.zoom
1626 state
.prevzoom
<- (conf
.zoom, state
.x);
1628 reshape state
.winw state
.winh
;
1629 state
.text <- Printf.sprintf
"zoom is now %-5.2f" (zoom *. 100.0);
1633 let pivotzoom ?
(vw=min state
.w state
.winw
)
1634 ?
(vh
=min
(state
.maxy-state
.y) state
.winh
)
1635 ?
(x=vw/2) ?
(y=vh
/2) zoom =
1636 let w = float state
.w /. zoom in
1637 let hw = w /. 2.0 in
1638 let ratio = float vh
/. float vw in
1639 let hh = hw *. ratio in
1640 let x0 = float x -. hw
1641 and y0 = float y -. hh in
1642 gotoxy (state
.x - truncate
x0) (state
.y + truncate
y0);
1646 let pivotzoom ?
vw ?vh ?
x ?
y zoom =
1647 if nogeomcmds state
.geomcmds
1650 then pivotzoom ?
vw ?vh ?
x ?
y zoom
1654 let setcolumns mode columns coverA coverB
=
1655 state
.prevcolumns
<- Some
(conf
.columns
, conf
.zoom);
1659 then impmsg "split mode doesn't work in bird's eye"
1661 conf
.columns
<- Csplit
(-columns
, E.a);
1669 conf
.columns
<- Csingle
E.a;
1674 conf
.columns
<- Cmulti
((columns
, coverA
, coverB
), E.a);
1678 reshape state
.winw state
.winh
;
1681 let resetmstate () =
1682 state
.mstate
<- Mnone
;
1683 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
1686 let enterbirdseye () =
1687 let zoom = float conf
.thumbw
/. float state
.winw
in
1688 let birdseyepageno =
1689 let cy = state
.winh
/ 2 in
1693 let rec fold best
= function
1696 let d = cy - (l.pagedispy + l.pagevh/2)
1697 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
1698 if abs
d < abs dbest
1707 { conf
with zoom = conf
.zoom },
1708 state
.x, birdseyepageno, -1, getanchor
()
1712 conf
.presentation
<- false;
1713 conf
.interpagespace
<- 10;
1714 conf
.hlinks
<- false;
1715 conf
.fitmodel
<- FitPage
;
1718 match conf
.beyecolumns
with
1721 Cmulti
((c, 0, 0), E.a)
1722 | None
-> Csingle
E.a
1726 state
.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1728 else state
.text <- E.s;
1729 reshape state
.winw state
.winh
;
1732 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
1734 conf
.zoom <- c.zoom;
1735 conf
.presentation
<- c.presentation
;
1736 conf
.interpagespace
<- c.interpagespace
;
1737 conf
.hlinks
<- c.hlinks
;
1738 conf
.fitmodel
<- c.fitmodel
;
1739 conf
.beyecolumns
<- (
1740 match conf
.columns
with
1741 | Cmulti
((c, _, _), _) -> Some
c
1743 | Csplit
_ -> error
"leaving bird's eye split mode"
1746 match c.columns
with
1747 | Cmulti
(c, _) -> Cmulti
(c, E.a)
1748 | Csingle
_ -> Csingle
E.a
1749 | Csplit
(c, _) -> Csplit
(c, E.a)
1753 state
.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1755 reshape state
.winw state
.winh
;
1756 state
.anchor <- if goback
then anchor else (pageno, 0.0, 1.0);
1760 let togglebirdseye () =
1761 match state
.mode
with
1762 | Birdseye vals
-> leavebirdseye vals
true
1763 | View
-> enterbirdseye ()
1764 | Textentry
_ | LinkNav
_ -> ()
1767 let upbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
1768 let pageno = max
0 (pageno - incr
) in
1769 let rec loop = function
1770 | [] -> gotopage1 pageno 0
1771 | l :: _ when l.pageno = pageno ->
1772 if l.pagedispy >= 0 && l.pagey = 0
1773 then postRedisplay
"upbirdseye"
1774 else gotopage1 pageno 0
1775 | _ :: rest
-> loop rest
1779 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor)
1782 let downbirdseye incr
(conf
, leftx
, pageno, hooverpageno
, anchor) =
1783 let pageno = min
(state
.pagecount
- 1) (pageno + incr
) in
1784 state
.mode
<- Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor);
1785 let rec loop = function
1787 let y, h = getpageyh
pageno in
1788 let dy = (y - state
.y) - (state
.winh
- h - conf
.interpagespace
) in
1789 gotoxy state
.x (clamp dy)
1790 | l :: _ when l.pageno = pageno ->
1791 if l.pagevh != l.pageh
1792 then gotoxy state
.x (clamp (l.pageh
- l.pagevh + conf
.interpagespace
))
1793 else postRedisplay
"downbirdseye"
1794 | _ :: rest
-> loop rest
1800 let optentry mode
_ key =
1801 let btos b = if b then "on" else "off" in
1802 match [@warning
"-4"] key with
1806 let n, a, b = multicolumns_of_string
s in
1807 setcolumns mode
n a b;
1809 state
.text <- Printf.sprintf
"bad columns `%s': %s" s @@ exntos exn
1811 TEswitch
("columns: ", E.s, None
, textentry, ondone, true)
1816 let zoom = float (int_of_string
s) /. 100.0 in
1819 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
1821 TEswitch
("zoom: ", E.s, None
, intentry, ondone, true)
1824 conf
.icase
<- not conf
.icase
;
1825 TEdone
("case insensitive search " ^
(btos conf
.icase
))
1828 conf
.verbose
<- not conf
.verbose
;
1829 TEdone
("verbose " ^
(btos conf
.verbose
))
1832 conf
.debug
<- not conf
.debug
;
1833 TEdone
("debug " ^
(btos conf
.debug
))
1836 conf
.underinfo
<- not conf
.underinfo
;
1837 TEdone
("underinfo " ^
btos conf
.underinfo
)
1840 settrim (not conf
.trimmargins
) conf
.trimfuzz
;
1841 TEdone
("trim margins " ^
btos conf
.trimmargins
)
1844 conf
.invert
<- not conf
.invert
;
1845 TEdone
("invert colors " ^
btos conf
.invert
)
1849 cbput state
.hists
.sel
s;
1852 TEswitch
("selection command: ", E.s, Some
(onhist state
.hists
.sel
),
1853 textentry, ondone, true)
1857 then conf
.pax
<- Some
0.0
1858 else conf
.pax
<- None
;
1859 TEdone
("PAX " ^
btos (conf
.pax
!= None
))
1862 state
.text <- Printf.sprintf
"bad option %d `%c'" (Char.code
c) c;
1865 | _ -> TEcont state
.text
1868 let adderrmsg src msg
=
1869 Buffer.add_string state
.errmsgs msg
;
1870 state
.newerrmsgs
<- true;
1874 let adderrfmt src fmt
= Format.ksprintf
(fun s -> adderrmsg src
s) fmt
;;
1876 class outlinelistview ~zebra ~source
=
1877 let settext autonarrow
s =
1880 let ss = source#statestr
in
1884 else "{" ^
ss ^
"} [" ^
s ^
"]"
1885 else state
.text <- s
1891 ~source
:(source
:> lvsource
)
1893 ~modehash
:(findkeyhash conf
"outline")
1896 val m_autonarrow
= false
1898 method! key key mask
=
1900 if emptystr state
.text
1902 else fstate
.maxrows - 2
1904 let calcfirst first active
=
1907 let rows = active
- first
in
1908 if rows > maxrows then active
- maxrows else first
1912 let active = m_active
+ incr
in
1913 let active = bound
active 0 (source#getitemcount
- 1) in
1914 let first = calcfirst m_first
active in
1915 postRedisplay
"outline navigate";
1916 coe
{< m_active
= active; m_first
= first >}
1918 let navscroll first =
1920 let dist = m_active
- first in
1926 else first + maxrows
1929 postRedisplay
"outline navscroll";
1930 coe
{< m_first
= first; m_active
= active >}
1932 let ctrl = Wsi.withctrl mask
in
1934 match Wsi.kc2kt
key with
1935 | Ascii '
a'
when ctrl ->
1943 let pattern = source#renarrow
in
1944 if nonemptystr m_qsearch
1945 then (source#narrow m_qsearch
; m_qsearch
)
1949 settext (not m_autonarrow
) text;
1950 postRedisplay
"toggle auto narrowing";
1951 coe
{< m_first
= 0; m_active
= 0; m_autonarrow
= not m_autonarrow
>}
1953 | Ascii '
/'
when emptystr m_qsearch
&& not m_autonarrow
->
1955 postRedisplay
"toggle auto narrowing";
1956 coe
{< m_first
= 0; m_active
= 0; m_autonarrow
= true >}
1958 | Ascii '
n'
when ctrl ->
1959 source#narrow m_qsearch
;
1961 then source#add_narrow_pattern m_qsearch
;
1962 postRedisplay
"outline ctrl-n";
1963 coe
{< m_first
= 0; m_active
= 0 >}
1965 | Ascii 'S'
when ctrl ->
1966 let active = source#calcactive
(getanchor
()) in
1967 let first = firstof m_first
active in
1968 postRedisplay
"outline ctrl-s";
1969 coe
{< m_first
= first; m_active
= active >}
1971 | Ascii 'u'
when ctrl ->
1972 postRedisplay
"outline ctrl-u";
1973 if m_autonarrow
&& nonemptystr m_qsearch
1975 ignore
(source#renarrow
);
1976 settext m_autonarrow
E.s;
1977 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
1980 source#del_narrow_pattern
;
1981 let pattern = source#renarrow
in
1983 if emptystr
pattern then E.s else "Narrowed to " ^
pattern
1985 settext m_autonarrow
text;
1986 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= E.s >}
1989 | Ascii '
l'
when ctrl ->
1990 let first = max
0 (m_active
- (fstate
.maxrows / 2)) in
1991 postRedisplay
"outline ctrl-l";
1992 coe
{< m_first
= first >}
1994 | Ascii '
\t'
when m_autonarrow
->
1995 if nonemptystr m_qsearch
1997 postRedisplay
"outline list view tab";
1998 source#add_narrow_pattern m_qsearch
;
2000 coe
{< m_qsearch
= E.s >}
2004 | Escape
when m_autonarrow
->
2005 if nonemptystr m_qsearch
2006 then source#add_narrow_pattern m_qsearch
;
2009 | Enter
when m_autonarrow
->
2010 if nonemptystr m_qsearch
2011 then source#add_narrow_pattern m_qsearch
;
2014 | (Ascii
_ | Code
_) when m_autonarrow
->
2015 let pattern = m_qsearch ^ toutf8
key in
2016 postRedisplay
"outlinelistview autonarrow add";
2017 source#narrow
pattern;
2018 settext true pattern;
2019 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
2021 | Backspace
when m_autonarrow
->
2022 if emptystr m_qsearch
2025 let pattern = withoutlastutf8 m_qsearch
in
2026 postRedisplay
"outlinelistview autonarrow backspace";
2027 ignore
(source#renarrow
);
2028 source#narrow
pattern;
2029 settext true pattern;
2030 coe
{< m_first
= 0; m_active
= 0; m_qsearch
= pattern >}
2032 | Up
when ctrl -> navscroll (max
0 (m_first
- 1))
2035 navscroll (min
(source#getitemcount
- 1) (m_first
+ 1))
2037 | Up
-> navigate ~
-1
2038 | Down
-> navigate 1
2039 | Prior
-> navigate ~
-(fstate
.maxrows)
2040 | Next
-> navigate fstate
.maxrows
2046 postRedisplay
"outline ctrl right";
2047 {< m_pan
= m_pan
+ 1 >}
2049 else self#updownlevel
1
2057 postRedisplay
"outline ctrl left";
2058 {< m_pan
= m_pan
- 1 >}
2060 else self#updownlevel ~
-1
2065 postRedisplay
"outline home";
2066 coe
{< m_first
= 0; m_active
= 0 >}
2069 let active = source#getitemcount
- 1 in
2070 let first = max
0 (active - fstate
.maxrows) in
2071 postRedisplay
"outline end";
2072 coe
{< m_active
= active; m_first
= first >}
2074 | Delete
|Escape
|Insert
|Enter
|Ascii
_|Code
_|Ctrl
_|Backspace
|Fn
_ ->
2078 let genhistoutlines () =
2080 |> List.sort
(fun (_, c1
, _, _, _, _) (_, c2
, _, _, _, _) ->
2081 compare c2
.lastvisit c1
.lastvisit
)
2082 |> List.map
(fun ((path
, c, _, _, _, origin
) as hist
) ->
2083 let path = if nonemptystr origin
then origin
else path in
2084 let base = mbtoutf8
@@ Filename.basename
path in
2085 (base ^
"\000" ^
c.title
, 1, Ohistory hist
)
2089 let gotohist (path, c, bookmarks
, x, anchor, origin
) =
2090 Config.save
leavebirdseye;
2091 state
.anchor <- anchor;
2092 state
.bookmarks
<- bookmarks
;
2093 state
.origin
<- origin
;
2096 let x0, y0, x1, y1 = conf
.trimfuzz
in
2097 wcmd "trimset %d %d %d %d %d" (btod conf
.trimmargins
) x0 y0 x1 y1;
2098 reshape ~firsttime
:true state
.winw state
.winh
;
2099 opendoc path origin
;
2103 let setcheckers enabled
=
2104 match state
.checkerstexid
with
2105 | None
-> if enabled
then state
.checkerstexid
<- Some
(makecheckers
())
2107 | Some checkerstexid
->
2110 GlTex.delete_texture checkerstexid
;
2111 state
.checkerstexid
<- None
;
2115 let describe_layout layout =
2119 | l :: [] -> Printf.sprintf
"Page %d" (l.pageno+1)
2122 if a.pageno = b.pageno then Printf.sprintf
"%d" (a.pageno+1)
2123 else Printf.sprintf
"%d%s%d" (a.pageno+1)
2124 (if a.pageno+1 = b.pageno then ", " else Utf8syms.ellipsis
)
2127 let rec fold s la lb
= function
2128 | [] -> Printf.sprintf
"%s %s" s (rangestr la lb
)
2129 | l :: rest
when l.pageno = succ lb
.pageno -> fold s la
l rest
2130 | l :: rest
-> fold (s ^
" " ^
rangestr la lb ^
",") l l rest
2132 fold "Pages" l l rest
2135 let maxy = maxy () in
2138 else 100. *. (float state
.y /. float maxy)
2140 Printf.sprintf
"%s of %d [%.2f%%]" d state
.pagecount
percent
2143 let setpresentationmode v
=
2144 let n = page_of_y state
.y in
2145 state
.anchor <- (n, 0.0, 1.0);
2146 conf
.presentation
<- v
;
2147 if conf
.fitmodel
= FitPage
2148 then reqlayout conf
.angle conf
.fitmodel
;
2153 let btos b = if b then Utf8syms.radical
else E.s in
2154 let showextended = ref false in
2155 let showcolors = ref false in
2156 let leave mode
_ = state
.mode
<- mode
in
2159 val mutable m_l
= []
2160 val mutable m_a
= E.a
2161 val mutable m_prev_uioh
= nouioh
2162 val mutable m_prev_mode
= View
2164 inherit lvsourcebase
2166 method reset prev_mode prev_uioh
=
2167 m_a
<- Array.of_list
(List.rev m_l
);
2169 m_prev_mode
<- prev_mode
;
2170 m_prev_uioh
<- prev_uioh
;
2172 method int name get
set =
2178 try set (int_of_string
s)
2180 state
.text <- Printf.sprintf
"bad integer `%s': %s"
2184 let te = name ^
": ", E.s, None
, intentry, ondone, true in
2185 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2189 method int_with_suffix name get
set =
2191 (name
, `intws get
, 1,
2195 try set (int_of_string_with_suffix
s)
2197 state
.text <- Printf.sprintf
"bad integer `%s': %s"
2202 name ^
": ", E.s, None
, intentry_with_suffix, ondone, true
2204 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2208 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
2210 (name
, `
bool (btos, get
), offset
, Action
(
2217 method color name get
set =
2219 (name
, `
color get
, 1,
2222 let invalid = (nan
, nan
, nan
) in
2225 try color_of_string
s
2227 state
.text <- Printf.sprintf
"bad color `%s': %s"
2234 let te = name ^
": ", E.s, None
, textentry, ondone, true in
2235 state
.text <- color_to_string
(get
());
2236 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2240 method string name get
set =
2242 (name
, `
string get
, 1,
2245 let ondone s = set s in
2246 let te = name ^
": ", E.s, None
, textentry, ondone, true in
2247 state
.mode
<- Textentry
(te, leave m_prev_mode
);
2251 method colorspace name get
set =
2253 (name
, `
string get
, 1,
2258 inherit lvsourcebase
2261 m_active
<- CSTE.to_int conf
.colorspace
;
2264 method getitemcount
=
2265 Array.length
CSTE.names
2268 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2269 ignore
(uioh
, first, pan
);
2270 if not cancel
then set active;
2272 method hasaction
_ = true
2276 let modehash = findkeyhash conf
"info" in
2277 coe
(new listview ~zebra
:false ~helpmode
:false
2278 ~
source ~trusted
:true ~
modehash)
2281 method paxmark name get
set =
2283 (name
, `
string get
, 1,
2288 inherit lvsourcebase
2291 m_active
<- MTE.to_int conf
.paxmark
;
2294 method getitemcount
= Array.length
MTE.names
2295 method getitem
n = (MTE.names
.(n), 0)
2296 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2297 ignore
(uioh
, first, pan
);
2298 if not cancel
then set active;
2300 method hasaction
_ = true
2304 let modehash = findkeyhash conf
"info" in
2305 coe
(new listview ~zebra
:false ~helpmode
:false
2306 ~
source ~trusted
:true ~
modehash)
2309 method fitmodel name get
set =
2311 (name
, `
string get
, 1,
2316 inherit lvsourcebase
2319 m_active
<- FMTE.to_int conf
.fitmodel
;
2322 method getitemcount
= Array.length
FMTE.names
2323 method getitem
n = (FMTE.names
.(n), 0)
2324 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2325 ignore
(uioh
, first, pan
);
2326 if not cancel
then set active;
2328 method hasaction
_ = true
2332 let modehash = findkeyhash conf
"info" in
2333 coe
(new listview ~zebra
:false ~helpmode
:false
2334 ~
source ~trusted
:true ~
modehash)
2337 method caption
s offset
=
2338 m_l
<- (s, `empty
, offset
, Noaction
) :: m_l
2340 method caption2
s f offset
=
2341 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
2343 method getitemcount
= Array.length m_a
2346 let tostr = function
2347 | `
int f -> string_of_int
(f ())
2348 | `intws
f -> string_with_suffix_of_int
(f ())
2350 | `
color f -> color_to_string
(f ())
2351 | `
bool (btos, f) -> btos (f ())
2354 let name, t
, offset
, _ = m_a
.(n) in
2355 ((let s = tostr t
in
2357 then Printf.sprintf
"%s\t%s" name s
2361 method exit ~uioh ~cancel ~
active ~
first ~pan
=
2366 match m_a
.(active) with
2367 | _, _, _, Action
f -> f uioh
2368 | _, _, _, Noaction
-> uioh
2379 method hasaction
n =
2381 | _, _, _, Action
_ -> true
2382 | _, _, _, Noaction
-> false
2384 initializer m_active
<- 1
2387 let rec fillsrc prevmode prevuioh
=
2388 let sep () = src#caption
E.s 0 in
2389 let colorp name get
set =
2391 (fun () -> color_to_string
(get
()))
2393 try set @@ color_of_string
v
2396 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
2399 let rgba name get
set =
2401 (fun () -> get
() |> rgba_to_string
)
2403 try set @@ rgba_of_string
v
2406 Printf.sprintf
"bad color `%s': %s" v @@ exntos exn
2409 let oldmode = state
.mode
in
2410 let birdseye = isbirdseye state
.mode
in
2412 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
2414 src#
bool "presentation mode"
2415 (fun () -> conf
.presentation
)
2416 (fun v -> setpresentationmode v);
2418 src#
bool "ignore case in searches"
2419 (fun () -> conf
.icase
)
2420 (fun v -> conf
.icase
<- v);
2423 (fun () -> conf
.preload)
2424 (fun v -> conf
.preload <- v);
2426 src#
bool "highlight links"
2427 (fun () -> conf
.hlinks
)
2428 (fun v -> conf
.hlinks
<- v);
2430 src#
bool "under info"
2431 (fun () -> conf
.underinfo
)
2432 (fun v -> conf
.underinfo
<- v);
2434 src#fitmodel
"fit model"
2435 (fun () -> FMTE.to_string conf
.fitmodel
)
2436 (fun v -> reqlayout conf
.angle
(FMTE.of_int
v));
2438 src#
bool "trim margins"
2439 (fun () -> conf
.trimmargins
)
2440 (fun v -> settrim v conf
.trimfuzz
; fillsrc prevmode prevuioh
);
2443 src#
int "inter-page space"
2444 (fun () -> conf
.interpagespace
)
2446 conf
.interpagespace
<- n;
2447 docolumns conf
.columns
;
2449 match state
.layout with
2451 | l :: _ -> l.pageno, l.pagey
2453 state
.maxy <- calcheight
();
2454 let y = getpagey
pageno in
2455 gotoxy state
.x (y + py)
2459 (fun () -> conf
.pagebias
)
2460 (fun v -> conf
.pagebias
<- v);
2462 src#
int "scroll step"
2463 (fun () -> conf
.scrollstep
)
2464 (fun n -> conf
.scrollstep
<- n);
2466 src#
int "horizontal scroll step"
2467 (fun () -> conf
.hscrollstep
)
2468 (fun v -> conf
.hscrollstep
<- v);
2470 src#
int "auto scroll step"
2472 match state
.autoscroll
with
2474 | _ -> conf
.autoscrollstep
)
2476 let n = boundastep state
.winh
n in
2477 if state
.autoscroll
<> None
2478 then state
.autoscroll
<- Some
n;
2479 conf
.autoscrollstep
<- n);
2482 (fun () -> truncate
(conf
.zoom *. 100.))
2483 (fun v -> pivotzoom ((float v) /. 100.));
2486 (fun () -> conf
.angle
)
2487 (fun v -> reqlayout v conf
.fitmodel
);
2489 src#
int "scroll bar width"
2490 (fun () -> conf
.scrollbw
)
2493 reshape state
.winw state
.winh
;
2496 src#
int "scroll handle height"
2497 (fun () -> conf
.scrollh
)
2498 (fun v -> conf
.scrollh
<- v;);
2500 src#
int "thumbnail width"
2501 (fun () -> conf
.thumbw
)
2503 conf
.thumbw
<- min
4096 v;
2506 leavebirdseye beye
false;
2513 let mode = state
.mode in
2514 src#
string "columns"
2516 match conf
.columns
with
2518 | Cmulti
(multi
, _) -> multicolumns_to_string multi
2519 | Csplit
(count
, _) -> "-" ^ string_of_int count
2522 let n, a, b = multicolumns_of_string
v in
2523 setcolumns mode n a b);
2526 src#caption
"Pixmap cache" 0;
2527 src#int_with_suffix
"size (advisory)"
2528 (fun () -> conf
.memlimit
)
2529 (fun v -> conf
.memlimit
<- v);
2533 Printf.sprintf
"%s bytes, %d tiles"
2534 (string_with_suffix_of_int state
.memused
)
2535 (Hashtbl.length state
.tilemap
)) 1;
2538 src#caption
"Layout" 0;
2539 src#caption2
"Dimension"
2540 (fun () -> Printf.sprintf
"%dx%d (virtual %dx%d)"
2541 state
.winw state
.winh
2545 then src#caption2
"Position" (fun () ->
2546 Printf.sprintf
"%dx%d" state
.x state
.y
2548 else src#caption2
"Position" (fun () -> describe_layout state
.layout) 1;
2551 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
2552 "Save these parameters as global defaults at exit"
2553 (fun () -> conf
.bedefault
)
2554 (fun v -> conf
.bedefault
<- v);
2557 let btos b = Utf8syms.(if b then lguillemet
else rguillemet
) in
2558 src#
bool ~offset
:0 ~
btos "Extended parameters"
2559 (fun () -> !showextended)
2560 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
2564 (fun () -> conf
.checkers
)
2565 (fun v -> conf
.checkers
<- v; setcheckers v);
2566 src#
bool "update cursor"
2567 (fun () -> conf
.updatecurs
)
2568 (fun v -> conf
.updatecurs
<- v);
2569 src#
bool "scroll-bar on the left"
2570 (fun () -> conf
.leftscroll
)
2571 (fun v -> conf
.leftscroll
<- v);
2573 (fun () -> conf
.verbose
)
2574 (fun v -> conf
.verbose
<- v);
2575 src#
bool "invert colors"
2576 (fun () -> conf
.invert
)
2577 (fun v -> conf
.invert
<- v);
2579 (fun () -> conf
.maxhfit
)
2580 (fun v -> conf
.maxhfit
<- v);
2582 (fun () -> conf
.pax
!= None
)
2585 then conf
.pax
<- Some
(now
())
2586 else conf
.pax
<- None
);
2587 src#
string "uri launcher"
2588 (fun () -> conf
.urilauncher
)
2589 (fun v -> conf
.urilauncher
<- v);
2590 src#
string "path launcher"
2591 (fun () -> conf
.pathlauncher
)
2592 (fun v -> conf
.pathlauncher
<- v);
2593 src#
string "tile size"
2594 (fun () -> Printf.sprintf
"%dx%d" conf
.tilew conf
.tileh
)
2597 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
2598 conf
.tilew
<- max
64 w;
2599 conf
.tileh
<- max
64 h;
2602 state
.text <- Printf.sprintf
"bad tile size `%s': %s"
2605 src#
int "texture count"
2606 (fun () -> conf
.texcount
)
2609 then conf
.texcount
<- v
2610 else impmsg "failed to set texture count please retry later"
2612 src#
int "slice height"
2613 (fun () -> conf
.sliceheight
)
2615 conf
.sliceheight
<- v;
2616 wcmd "sliceh %d" conf
.sliceheight
;
2618 src#
int "anti-aliasing level"
2619 (fun () -> conf
.aalevel
)
2621 conf
.aalevel
<- bound
v 0 8;
2622 state
.anchor <- getanchor
();
2623 opendoc state
.path state
.password;
2625 src#
string "page scroll scaling factor"
2626 (fun () -> string_of_float conf
.pgscale)
2628 try conf
.pgscale <- float_of_string
v
2631 Printf.sprintf
"bad page scroll scaling factor `%s': %s" v
2634 src#
int "ui font size"
2635 (fun () -> fstate
.fontsize
)
2636 (fun v -> setfontsize (bound
v 5 100));
2637 src#
int "hint font size"
2638 (fun () -> conf
.hfsize
)
2639 (fun v -> conf
.hfsize
<- bound
v 5 100);
2640 src#
string "trim fuzz"
2641 (fun () -> irect_to_string conf
.trimfuzz
)
2644 conf
.trimfuzz
<- irect_of_string
v;
2646 then settrim true conf
.trimfuzz
;
2648 state
.text <- Printf.sprintf
"bad irect `%s': %s" v
2651 src#
string "selection command"
2652 (fun () -> conf
.selcmd
)
2653 (fun v -> conf
.selcmd
<- v);
2654 src#
string "synctex command"
2655 (fun () -> conf
.stcmd
)
2656 (fun v -> conf
.stcmd
<- v);
2657 src#
string "pax command"
2658 (fun () -> conf
.paxcmd
)
2659 (fun v -> conf
.paxcmd
<- v);
2660 src#
string "ask password command"
2661 (fun () -> conf
.passcmd)
2662 (fun v -> conf
.passcmd <- v);
2663 src#
string "save path command"
2664 (fun () -> conf
.savecmd
)
2665 (fun v -> conf
.savecmd
<- v);
2666 src#colorspace
"color space"
2667 (fun () -> CSTE.to_string conf
.colorspace
)
2669 conf
.colorspace
<- CSTE.of_int
v;
2673 src#paxmark
"pax mark method"
2674 (fun () -> MTE.to_string conf
.paxmark
)
2675 (fun v -> conf
.paxmark
<- MTE.of_int
v);
2676 if bousable
() && !opengl_has_pbo
2679 (fun () -> conf
.usepbo
)
2680 (fun v -> conf
.usepbo
<- v);
2681 src#
bool "mouse wheel scrolls pages"
2682 (fun () -> conf
.wheelbypage
)
2683 (fun v -> conf
.wheelbypage
<- v);
2684 src#
bool "open remote links in a new instance"
2685 (fun () -> conf
.riani
)
2686 (fun v -> conf
.riani
<- v);
2687 src#
bool "edit annotations inline"
2688 (fun () -> conf
.annotinline
)
2689 (fun v -> conf
.annotinline
<- v);
2690 src#
bool "coarse positioning in presentation mode"
2691 (fun () -> conf
.coarseprespos
)
2692 (fun v -> conf
.coarseprespos
<- v);
2693 src#
bool "use document CSS"
2694 (fun () -> conf
.usedoccss
)
2696 conf
.usedoccss
<- v;
2697 state
.anchor <- getanchor
();
2698 opendoc state
.path state
.password;
2700 src#
bool ~
btos "colors"
2701 (fun () -> !showcolors)
2702 (fun v -> showcolors := v; fillsrc prevmode prevuioh
);
2705 colorp " background"
2706 (fun () -> conf
.bgcolor
)
2707 (fun v -> conf
.bgcolor
<- v);
2709 (fun () -> conf
.sbarcolor
)
2710 (fun v -> conf
.sbarcolor
<- v);
2711 rgba " scrollbar handle"
2712 (fun () -> conf
.sbarhndlcolor
)
2713 (fun v -> conf
.sbarhndlcolor
<- v);
2718 src#caption
"Document" 0;
2719 List.iter
(fun (_, s) -> src#caption
s 1) state
.docinfo
;
2720 src#caption2
"Pages"
2721 (fun () -> string_of_int state
.pagecount
) 1;
2722 src#caption2
"Dimensions"
2723 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
2724 if nonemptystr conf
.css
2725 then src#caption2
"CSS" (fun () -> conf
.css
) 1;
2729 src#caption
"Trimmed margins" 0;
2730 src#caption2
"Dimensions"
2731 (fun () -> string_of_int
(List.length state
.pdims
)) 1;
2735 src#caption
"OpenGL" 0;
2736 src#caption
(Printf.sprintf
"Vendor\t%s" (GlMisc.get_string `vendor
)) 1;
2737 src#caption
(Printf.sprintf
"Renderer\t%s" (GlMisc.get_string `renderer
)) 1;
2740 src#caption
"Location" 0;
2741 if nonemptystr state
.origin
2742 then src#caption
("Orign\t" ^ mbtoutf8 state
.origin
) 1;
2743 src#caption
("Path\t" ^ mbtoutf8 state
.path) 1;
2745 src#reset prevmode prevuioh
;
2750 let prevmode = state
.mode
2751 and prevuioh
= state
.uioh in
2752 fillsrc prevmode prevuioh
;
2753 let source = (src :> lvsource
) in
2754 let modehash = findkeyhash conf
"info" in
2757 inherit listview ~zebra
:false ~helpmode
:false
2758 ~
source ~trusted
:true ~
modehash as super
2759 val mutable m_prevmemused
= 0
2760 method! infochanged
= function
2762 if m_prevmemused
!= state
.memused
2764 m_prevmemused
<- state
.memused
;
2765 postRedisplay
"memusedchanged";
2767 | Pdim
-> postRedisplay
"pdimchanged"
2768 | Docinfo
-> fillsrc prevmode prevuioh
2770 method! key key mask
=
2771 if not
(Wsi.withctrl mask
)
2773 match [@warning
"-4"] Wsi.kc2kt
key with
2774 | Keys.Left
-> coe
(self#updownlevel ~
-1)
2775 | Keys.Right
-> coe
(self#updownlevel
1)
2776 | _ -> super#
key key mask
2777 else super#
key key mask
2779 postRedisplay
"info";
2785 inherit lvsourcebase
2786 method getitemcount
= Array.length state
.help
2788 let s, l, _ = state
.help
.(n) in
2791 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2795 match state
.help
.(active) with
2796 | _, _, Action
f -> Some
(f uioh)
2797 | _, _, Noaction
-> Some
uioh
2806 method hasaction
n =
2807 match state
.help
.(n) with
2808 | _, _, Action
_ -> true
2809 | _, _, Noaction
-> false
2815 let modehash = findkeyhash conf
"help" in
2817 state
.uioh <- coe
(new listview
2818 ~zebra
:false ~helpmode
:true
2819 ~
source ~trusted
:true ~
modehash);
2820 postRedisplay
"help";
2826 inherit lvsourcebase
2827 val mutable m_items
= E.a
2829 method getitemcount
= 1 + Array.length m_items
2834 else m_items
.(n-1), 0
2836 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2841 then Buffer.clear state
.errmsgs
;
2848 method hasaction
n =
2852 state
.newerrmsgs
<- false;
2853 let l = Str.split
Utils.Re.crlf
(Buffer.contents state
.errmsgs
) in
2854 m_items
<- Array.of_list
l
2863 let source = (msgsource :> lvsource
) in
2864 let modehash = findkeyhash conf
"listview" in
2867 inherit listview ~zebra
:false ~helpmode
:false
2868 ~
source ~trusted
:false ~
modehash as super
2871 then msgsource#reset
;
2874 postRedisplay
"msgs";
2878 let editor = getenvwithdef
"EDITOR" E.s in
2882 let tmppath = Filename.temp_file
"llpp" "note" in
2885 let oc = open_out
tmppath in
2889 let execstr = editor ^
" " ^
tmppath in
2891 match spawn
execstr [] with
2893 impmsg "spawn(%S) failed: %s" execstr @@ exntos exn
;
2896 match Unix.waitpid
[] pid
with
2898 impmsg "waitpid(%d) failed: %s" pid
@@ exntos exn
;
2902 | Unix.WEXITED
0 -> filecontents
tmppath
2904 impmsg "editor process(%s) exited abnormally: %d" execstr n;
2906 | Unix.WSIGNALED
n ->
2907 impmsg "editor process(%s) was killed by signal %d" execstr n;
2909 | Unix.WSTOPPED
n ->
2910 impmsg "editor(%s) process was stopped by signal %d" execstr n;
2913 match Unix.unlink
tmppath with
2915 impmsg "failed to ulink %S: %s" tmppath @@ exntos exn
;
2920 let enterannotmode opaque slinkindex
=
2923 inherit lvsourcebase
2924 val mutable m_text
= E.s
2925 val mutable m_items
= E.a
2927 method getitemcount
= Array.length m_items
2930 let label, _func
= m_items
.(n) in
2933 method exit ~
uioh ~cancel ~
active ~
first ~pan
=
2934 ignore
(uioh, first, pan
);
2937 let _label, func
= m_items
.(active) in
2942 method hasaction
n = nonemptystr
@@ fst m_items
.(n)
2945 let rec split accu b i
=
2947 if p = String.length
s
2948 then (String.sub s b (p-b), unit) :: accu
2950 if (i
> 70 && s.[p] = ' '
) || s.[p] = '
\r'
|| s.[p] = '
\n'
2952 let ss = if i
= 0 then E.s else String.sub s b i
in
2953 split ((ss, unit)::accu) (p+1) 0
2954 else split accu b (i
+1)
2957 wcmd "freepage %s" (~
> opaque);
2959 Hashtbl.fold (fun key opaque'
accu ->
2960 if opaque'
= opaque'
2961 then key :: accu else accu) state
.pagemap
[]
2963 List.iter
(Hashtbl.remove state
.pagemap
) keys;
2965 gotoxy state
.x state
.y
2968 delannot
opaque slinkindex
;
2971 let edit inline
() =
2976 modannot
opaque slinkindex
s;
2982 let mode = state
.mode in
2985 ("annotation: ", m_text
, None
, textentry, update, true),
2986 fun _ -> state
.mode <- mode
2991 let s = getusertext m_text
in
2996 ( "[Copy]", fun () -> selstring conf
.selcmd m_text
)
2997 :: ("[Delete]", dele)
2998 :: ("[Edit]", edit conf
.annotinline
)
3000 :: split [] 0 0 |> List.rev
|> Array.of_list
3007 let s = getannotcontents
opaque slinkindex
in
3010 let source = (msgsource :> lvsource
) in
3011 let modehash = findkeyhash conf
"listview" in
3012 state
.uioh <- coe
(object
3013 inherit listview ~zebra
:false ~helpmode
:false
3014 ~
source ~trusted
:false ~
modehash
3016 postRedisplay
"enterannotmode";
3019 let gotoremote spec
=
3020 let filename, dest
= splitatchar spec '#'
in
3021 let getpath filename =
3023 if nonemptystr
filename
3025 if Filename.is_relative
filename
3027 let dir = Filename.dirname state
.path in
3029 if Filename.is_implicit
dir
3030 then Filename.concat
(Sys.getcwd
()) dir
3033 Filename.concat
dir filename
3037 if Sys.file_exists
path
3041 let path = getpath filename in
3045 let cmd = Lazy.force_val lcmd
in
3046 match spawn
cmd with
3048 | exception exn
-> dolog
"failed to execute `%s': %s" cmd @@ exntos exn
3050 let anchor = getanchor
() in
3051 let ranchor = state
.path, state
.password, anchor, state
.origin
in
3052 state
.origin
<- E.s;
3053 state
.ranchors
<- ranchor :: state
.ranchors
;
3056 if substratis spec
0 "page="
3058 match Scanf.sscanf spec
"page=%d" (fun n -> n) with
3060 state
.anchor <- (pageno, 0.0, 0.0);
3061 dospawn @@ lazy (Printf.sprintf
"%s -page %d %S" !selfexec pageno path);
3063 adderrfmt "error parsing remote destination" "page: %s" @@ exntos exn
3065 state
.nameddest
<- dest
;
3066 dospawn @@ lazy (!selfexec ^
" " ^
path ^
" -dest " ^ dest
)
3070 let gotounder = function
3071 | Ulinkuri
s when isexternallink
s ->
3072 if substratis
s 0 "file://"
3073 then gotoremote @@ String.sub s 7 (String.length
s - 7)
3074 else Help.gotouri conf
.urilauncher
s
3076 let pageno, x, y = uritolocation
s in
3078 gotopagexy pageno x y
3079 | Utext
_ | Unone
-> ()
3080 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
3083 let gotooutline (_, _, kind
) =
3087 let (pageno, y, _) = anchor in
3089 (if conf
.presentation
then (pageno, y, 1.0) else anchor)
3093 | Ouri
uri -> gotounder (Ulinkuri
uri)
3094 | Olaunch
cmd -> error
"gotounder (Ulaunch %S)" cmd
3095 | Oremote
(remote
, pageno) ->
3096 error
"gotounder (Uremote (%S,%d) )" remote
pageno
3097 | Ohistory hist
-> gotohist hist
3098 | Oremotedest
(path, dest
) ->
3099 error
"gotounder (Uremotedest (%S, %S))" path dest
3102 class outlinesoucebase fetchoutlines
= object (self
)
3103 inherit lvsourcebase
3104 val mutable m_items
= E.a
3105 val mutable m_minfo
= E.a
3106 val mutable m_orig_items
= E.a
3107 val mutable m_orig_minfo
= E.a
3108 val mutable m_narrow_patterns
= []
3109 val mutable m_gen
= -1
3111 method getitemcount
= Array.length m_items
3114 let s, n, _ = m_items
.(n) in
3117 method exit ~
(uioh:uioh) ~cancel ~
active ~
(first:int) ~pan
: uioh option =
3118 ignore
(uioh, first);
3120 if m_narrow_patterns
= []
3121 then m_orig_items
, m_orig_minfo
3122 else m_items
, m_minfo
3129 gotooutline m_items
.(active);
3137 method hasaction
(_:int) = true
3140 if Array.length m_items
!= Array.length m_orig_items
3143 match m_narrow_patterns
with
3145 | many
-> String.concat
Utf8syms.ellipsis
(List.rev many
)
3147 "Narrowed to " ^
s ^
" (ctrl-u to restore)"
3151 match m_narrow_patterns
with
3154 | head
:: _ -> Utf8syms.ellipsis ^ head
3156 method narrow
pattern =
3157 match Str.regexp_case_fold
pattern with
3160 let rec loop accu minfo
n =
3163 m_items
<- Array.of_list
accu;
3164 m_minfo
<- Array.of_list minfo
;
3167 let (s, _, _) as o = m_items
.(n) in
3169 match Str.search_forward re
s 0 with
3170 | exception Not_found
-> accu, minfo
3171 | first -> o :: accu, (first, Str.match_end
()) :: minfo
3173 loop accu minfo
(n-1)
3175 loop [] [] (Array.length m_items
- 1)
3177 method! getminfo
= m_minfo
3180 m_orig_items
<- fetchoutlines
();
3181 m_minfo
<- m_orig_minfo
;
3182 m_items
<- m_orig_items
3184 method add_narrow_pattern
pattern =
3185 m_narrow_patterns
<- pattern :: m_narrow_patterns
3187 method del_narrow_pattern
=
3188 match m_narrow_patterns
with
3189 | _ :: rest
-> m_narrow_patterns
<- rest
3194 match m_narrow_patterns
with
3195 | pattern :: [] -> self#narrow
pattern; pattern
3197 List.fold_left
(fun accu pattern ->
3198 self#narrow
pattern;
3199 pattern ^
Utf8syms.ellipsis ^
accu) E.s list
3201 method calcactive
(_:anchor) = 0
3203 method reset
anchor items =
3204 if state
.gen
!= m_gen
3206 m_orig_items
<- items;
3208 m_narrow_patterns
<- [];
3210 m_orig_minfo
<- E.a;
3214 if items != m_orig_items
3216 m_orig_items
<- items;
3217 if m_narrow_patterns
== []
3218 then m_items
<- items;
3221 let active = self#calcactive
anchor in
3223 m_first
<- firstof m_first
active
3227 let outlinesource fetchoutlines
=
3229 inherit outlinesoucebase fetchoutlines
3230 method! calcactive
anchor =
3231 let rely = getanchory anchor in
3232 let rec loop n best bestd
=
3233 if n = Array.length m_items
3236 let _, _, kind
= m_items
.(n) in
3239 let orely = getanchory anchor in
3240 let d = abs
(orely - rely) in
3243 else loop (n+1) best bestd
3244 | Onone
| Oremote
_ | Olaunch
_
3245 | Oremotedest
_ | Ouri
_ | Ohistory
_ ->
3246 loop (n+1) best bestd
3252 let enteroutlinemode, enterbookmarkmode
, enterhistmode
=
3253 let mkselector sourcetype
=
3254 let fetchoutlines () =
3255 match sourcetype
with
3256 | `bookmarks
-> Array.of_list state
.bookmarks
3257 | `outlines
-> state
.outlines
3258 | `history
-> genhistoutlines () |> Array.of_list
3261 if sourcetype
= `history
3262 then new outlinesoucebase
fetchoutlines
3263 else outlinesource fetchoutlines
3266 let outlines = fetchoutlines () in
3267 if Array.length
outlines = 0
3268 then showtext ' ' errmsg
3271 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3272 let anchor = getanchor
() in
3273 source#reset
anchor outlines;
3274 state
.text <- source#greetmsg
;
3276 coe
(new outlinelistview ~zebra
:(sourcetype
=`history
) ~
source);
3277 postRedisplay
"enter selector";
3281 let mkenter sourcetype errmsg
= fun () -> mkselector sourcetype errmsg
in
3282 ( mkenter `
outlines "document has no outline"
3283 , mkenter `bookmarks
"document has no bookmarks (yet)"
3284 , mkenter `history
"history is empty" )
3287 let quickbookmark ?title
() =
3288 match state
.layout with
3295 let tm = localtime
(now
()) in
3297 "Quick (page %d) (bookmarked on %02d/%02d/%d at %02d:%02d)"
3299 tm.tm_mday
(tm.tm_mon
+1) (tm.tm_year
+1900) tm.tm_hour
tm.tm_min
3301 | Some
title -> title
3303 state
.bookmarks
<- (title, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
3306 let setautoscrollspeed step goingdown
=
3307 let incr = max
1 ((abs step
) / 2) in
3308 let incr = if goingdown
then incr else -incr in
3309 let astep = boundastep state
.winh
(step
+ incr) in
3310 state
.autoscroll
<- Some
astep;
3314 match conf
.columns
with
3316 | Csingle
_ | Cmulti
_ -> state
.x != 0 || conf
.zoom > 1.0
3319 let panbound x = bound
x (-state
.w) state
.winw
;;
3321 let existsinrow pageno (columns
, coverA
, coverB
) p =
3322 let last = ((pageno - coverA
) mod columns
) + columns
in
3323 let rec any = function
3326 if l.pageno = coverA
- 1 || l.pageno = state
.pagecount
- coverB
3330 then (if l.pageno = last then false else any rest
)
3338 match state
.layout with
3340 let pageno = page_of_y state
.y in
3341 gotoxy state
.x (getpagey
(pageno+1))
3343 match conf
.columns
with
3345 if conf
.presentation
&& rest
== [] && l.pageh
> l.pagey + l.pagevh
3347 let y = clamp (pgscale state
.winh
) in
3350 let pageno = min
(l.pageno+1) (state
.pagecount
-1) in
3351 gotoxy state
.x (getpagey
pageno)
3352 | Cmulti
((c, _, _) as cl
, _) ->
3353 if conf
.presentation
3354 && (existsinrow l.pageno cl
3355 (fun l -> l.pageh
> l.pagey + l.pagevh))
3357 let y = clamp (pgscale state
.winh
) in
3360 let pageno = min
(l.pageno+c) (state
.pagecount
-1) in
3361 gotoxy state
.x (getpagey
pageno)
3363 if l.pageno < state
.pagecount
- 1 || l.pagecol
< n - 1
3365 let pagey, pageh
= getpageyh
l.pageno in
3366 let pagey = pagey + pageh
* l.pagecol
in
3367 let ips = if l.pagecol
= 0 then 0 else conf
.interpagespace
in
3368 gotoxy state
.x (pagey + pageh
+ ips)
3372 match state
.layout with
3374 let pageno = page_of_y state
.y in
3375 gotoxy state
.x (getpagey
(pageno-1))
3377 match conf
.columns
with
3379 if conf
.presentation
&& l.pagey != 0
3381 gotoxy state
.x (clamp (pgscale ~
-(state
.winh
)))
3383 let pageno = max
0 (l.pageno-1) in
3384 gotoxy state
.x (getpagey
pageno)
3385 | Cmulti
((c, _, coverB
) as cl
, _) ->
3386 if conf
.presentation
&&
3387 (existsinrow l.pageno cl
(fun l -> l.pagey != 0))
3389 gotoxy state
.x (clamp (pgscale ~
-(state
.winh
)))
3392 if l.pageno = state
.pagecount
- coverB
3396 let pageno = max
0 (l.pageno-decr) in
3397 gotoxy state
.x (getpagey
pageno)
3405 let pageno = max
0 (l.pageno-1) in
3406 let pagey, pageh
= getpageyh
pageno in
3409 let pagey, pageh
= getpageyh
l.pageno in
3410 pagey + pageh
* (l.pagecol
-1) - conf
.interpagespace
3416 if emptystr conf
.savecmd
3417 then adderrmsg "savepath-command is empty"
3418 "don't know where to save modified document"
3420 let savecmd = Str.global_replace
Utils.Re.percent state
.path conf
.savecmd in
3424 adderrfmt savecmd "failed to produce path to the saved copy: %s" exn
)
3429 let tmp = path ^
".tmp" in
3431 Unix.rename
tmp path;
3434 let viewkeyboard key mask
=
3436 let mode = state
.mode in
3437 state
.mode <- Textentry
(te, fun _ -> state
.mode <- mode);
3440 postRedisplay
"view:enttext"
3442 let ctrl = Wsi.withctrl mask
in
3444 match Wsi.kc2kt
key with
3445 | Ascii 'S'
-> state
.slideshow
<- state
.slideshow
lxor 1
3447 | Ascii 'Q'
-> exit
0
3450 if hasunsavedchanges
()
3454 if conf
.angle
mod 360 = 0 && not
(isbirdseye state
.mode)
3457 match state
.lnava
with
3458 | None
-> LinkNav
(Ltgendir
0)
3459 | Some
pn -> LinkNav
(Ltexact
pn)
3461 gotoxy state
.x state
.y;
3463 else impmsg "keyboard link navigation does not work under rotation"
3465 | Escape
| Ascii 'q'
->
3466 begin match state
.mstate
with
3469 postRedisplay
"kill rect";
3472 | Mscrolly
| Mscrollx
3475 begin match state
.mode with
3478 | Ltexact pl
-> state
.lnava
<- Some pl
3479 | Ltgendir
_ | Ltnotready
_ -> state
.lnava
<- None
3482 postRedisplay
"esc leave linknav"
3483 | Birdseye
_ | Textentry
_ | View
->
3484 match state
.ranchors
with
3486 | (path, password, anchor, origin
) :: rest
->
3487 state
.ranchors
<- rest
;
3488 state
.anchor <- anchor;
3489 state
.origin
<- origin
;
3490 state
.nameddest
<- E.s;
3491 opendoc path password
3497 gotoxy state
.x (getnav ~
-1)
3508 Hashtbl.iter
(fun _ opaque ->
3510 Hashtbl.clear state
.prects
) state
.pagemap
;
3511 postRedisplay
"dehighlight";
3513 | Ascii
(('
/'
| '?'
) as c) ->
3514 let ondone isforw
s =
3515 cbput state
.hists
.pat
s;
3516 state
.searchpattern
<- s;
3519 let s = String.make
1 c in
3520 enttext (s, E.s, Some
(onhist state
.hists
.pat
),
3521 textentry, ondone (c = '
/'
), true)
3523 | Ascii '
+'
| Ascii '
='
when ctrl ->
3524 let incr = if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
3525 pivotzoom (conf
.zoom +. incr)
3530 try int_of_string
s with exn
->
3532 Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
3538 state
.text <- "page bias is now " ^ string_of_int
n;
3541 enttext ("page bias: ", E.s, None
, intentry, ondone, true)
3543 | Ascii '
-'
when ctrl ->
3544 let decr = if conf
.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
3545 pivotzoom (max
0.01 (conf
.zoom -. decr))
3548 let ondone msg
= state
.text <- msg
in
3549 enttext ("option: ", E.s, None
,
3550 optentry state
.mode, ondone, true)
3552 | Ascii '
0'
when ctrl ->
3554 then gotoxy 0 state
.y
3557 | Ascii
('
1'
|'
2'
as c) when ctrl && conf
.fitmodel
!= FitPage
->
3559 match conf
.columns
with
3560 | Csingle
_ | Cmulti
_ -> 1
3561 | Csplit
(n, _) -> n
3563 let h = state
.winh
-
3564 conf
.interpagespace
lsl (if conf
.presentation
then 1 else 0)
3566 let zoom = zoomforh state
.winw
h 0 cols in
3567 if zoom > 0.0 && (c = '
2'
|| zoom < 1.0)
3570 | Ascii '
3'
when ctrl ->
3572 match conf
.fitmodel
with
3573 | FitWidth
-> FitProportional
3574 | FitProportional
-> FitPage
3575 | FitPage
-> FitWidth
3577 state
.text <- "fit model: " ^
FMTE.to_string
fm;
3578 reqlayout conf
.angle
fm
3580 | Ascii '
4'
when ctrl ->
3581 let zoom = getmaxw
() /. float state
.winw
in
3582 if zoom > 0.0 then setzoom zoom
3584 | Fn
9 | Ascii '
9'
when ctrl -> togglebirdseye ()
3586 | Ascii
('
0'
..'
9'
as c) when not
ctrl ->
3589 try int_of_string
s with exn
->
3590 state
.text <- Printf.sprintf
"bad integer `%s': %s" s @@ exntos exn
;
3596 cbput state
.hists
.pag
(string_of_int
n);
3597 gotopage1 (n + conf
.pagebias
- 1) 0;
3600 let pageentry text = function [@warning
"-4"]
3601 | Keys.Ascii '
g'
-> TEdone
text
3602 | key -> intentry text key
3604 let text = String.make
1 c in
3605 enttext (":", text, Some
(onhist state
.hists
.pag
),
3606 pageentry, ondone, true)
3609 conf
.scrollb
<- if conf
.scrollb
= 0 then (scrollbvv
lor scrollbhv
) else 0;
3610 postRedisplay
"toggle scrollbar";
3613 state
.bzoom
<- not state
.bzoom
;
3615 showtext ' '
("block zoom " ^
if state
.bzoom
then "on" else "off")
3618 conf
.hlinks
<- not conf
.hlinks
;
3619 state
.text <- "highlightlinks " ^
if conf
.hlinks
then "on" else "off";
3620 postRedisplay
"toggle highlightlinks";
3623 if conf
.angle
mod 360 = 0
3625 state
.glinks
<- true;
3626 let mode = state
.mode in
3629 (":", E.s, None
, linknentry, linknact gotounder, false),
3631 state
.glinks
<- false;
3635 postRedisplay
"view:linkent(F)"
3637 else impmsg "hint mode does not work under rotation"
3640 state
.glinks
<- true;
3641 let mode = state
.mode in
3644 (":", E.s, None
, linknentry,
3645 linknact (fun under ->
3646 selstring conf
.selcmd
(undertext under)), false),
3648 state
.glinks
<- false;
3652 postRedisplay
"view:linkent"
3655 begin match state
.autoscroll
with
3657 conf
.autoscrollstep
<- step
;
3658 state
.autoscroll
<- None
3660 state
.autoscroll
<- Some conf
.autoscrollstep
;
3661 state
.slideshow
<- state
.slideshow
land lnot
2
3664 | Ascii '
p'
when ctrl ->
3665 launchpath () (* XXX where do error messages go? *)
3668 setpresentationmode (not conf
.presentation
);
3669 showtext ' '
("presentation mode " ^
3670 if conf
.presentation
then "on" else "off");
3673 if List.mem
Wsi.Fullscreen state
.winstate
3674 then Wsi.reshape conf
.cwinw conf
.cwinh
3675 else Wsi.fullscreen
()
3677 | Ascii
('
p'
|'N'
) ->
3678 search state
.searchpattern
false
3680 | Ascii '
n'
| Fn
3 ->
3681 search state
.searchpattern
true
3684 begin match state
.layout with
3686 | l :: _ -> gotoxy state
.x (getpagey
l.pageno)
3689 | Ascii ' '
-> nextpage ()
3690 | Delete
-> prevpage ()
3691 | Ascii '
='
-> showtext ' '
(describe_layout state
.layout);
3694 begin match state
.layout with
3697 Wsi.reshape l.pagew
l.pageh
;
3701 | Ascii '
\''
-> enterbookmarkmode
()
3702 | Ascii '
h'
| Fn
1 -> enterhelpmode ()
3703 | Ascii 'i'
-> enterinfomode ()
3704 | Ascii '
e'
when Buffer.length state
.errmsgs
> 0 -> entermsgsmode ()
3708 match state
.layout with
3709 | l :: _ when nonemptystr
s ->
3710 state
.bookmarks
<- (s, 0, Oanchor
(getanchor1
l)) :: state
.bookmarks
3713 enttext ("bookmark: ", E.s, None
, textentry, ondone, true)
3717 showtext ' '
"Quick bookmark added";
3719 | Ascii '
x'
-> state
.roam
()
3721 | Ascii
('
<'
|'
>'
as c) ->
3722 reqlayout (conf
.angle
+ (if c = '
>'
then 30 else -30)) conf
.fitmodel
3724 | Ascii
('
['
|'
]'
as c) ->
3726 bound
(conf
.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0;
3727 postRedisplay
"brightness";
3729 | Ascii '
c'
when state
.mode = View
->
3734 let m = (state
.winw
- state
.w) / 2 in
3739 match state
.prevcolumns
with
3740 | None
-> (1, 0, 0), 1.0
3741 | Some
(columns
, z
) ->
3744 | Csplit
(c, _) -> -c, 0, 0
3745 | Cmulti
((c, a, b), _) -> c, a, b
3746 | Csingle
_ -> 1, 0, 0
3750 setcolumns View
c a b;
3753 | Down
| Up
when ctrl && Wsi.withshift mask
->
3754 let zoom, x = state
.prevzoom
in
3759 begin match state
.autoscroll
with
3761 begin match state
.mode with
3762 | Birdseye beye
-> upbirdseye 1 beye
3763 | Textentry
_ | View
| LinkNav
_ ->
3765 then gotoxy state
.x (clamp ~
-(state
.winh
/2))
3767 if not
(Wsi.withshift mask
) && conf
.presentation
3769 else gotoxy state
.x (clamp (-conf
.scrollstep
))
3772 | Some
n -> setautoscrollspeed n false
3775 | Ascii 'j'
| Down
->
3776 begin match state
.autoscroll
with
3778 begin match state
.mode with
3779 | Birdseye beye
-> downbirdseye 1 beye
3780 | Textentry
_ | View
| LinkNav
_ ->
3782 then gotoxy state
.x (clamp (state
.winh
/2))
3784 if not
(Wsi.withshift mask
) && conf
.presentation
3786 else gotoxy state
.x (clamp (conf
.scrollstep
))
3789 | Some
n -> setautoscrollspeed n true
3792 | Left
| Right
when not
(Wsi.withalt mask
) ->
3798 else conf
.hscrollstep
3801 let pv = Wsi.kc2kt
key in
3802 if pv = Keys.Left
then dx else -dx
3804 gotoxy (panbound (state
.x + dx)) state
.y
3807 postRedisplay
"left/right"
3814 match state
.layout with
3816 | l :: _ -> state
.y - l.pagey
3817 else clamp (pgscale (-state
.winh
))
3825 match List.rev state
.layout with
3827 | l :: _ -> getpagey
l.pageno
3828 else clamp (pgscale state
.winh
)
3832 | Ascii '
g'
| Home
->
3835 | Ascii 'G'
| End
->
3837 gotoxy 0 (clamp state
.maxy)
3839 | Right
when Wsi.withalt mask
->
3841 gotoxy state
.x (getnav 1)
3842 | Left
when Wsi.withalt mask
->
3844 gotoxy state
.x (getnav ~
-1)
3849 | Ascii '
v'
when conf
.debug
->
3852 match getopaque l.pageno with
3855 let x0, y0, x1, y1 = pagebbox
opaque in
3856 let rect = (float x0, float y0,
3859 float x0, float y1) in
3861 let color = (0.0, 0.0, 1.0 /. (l.pageno mod 3 |> float), 0.5) in
3862 state
.rects
<- (l.pageno, color, rect) :: state
.rects
;
3867 let mode = state
.mode in
3868 let cmd = ref E.s in
3869 let onleave = function
3870 | Cancel
-> state
.mode <- mode
3873 match getopaque l.pageno with
3874 | Some
opaque -> pipesel opaque !cmd
3875 | None
-> ()) state
.layout;
3879 cbput state
.hists
.sel
s;
3883 "| ", !cmd, Some
(onhist state
.hists
.sel
), textentry, ondone, true
3886 state
.mode <- Textentry
(te, onleave);
3888 | (Ascii
_|Fn
_|Enter
|Left
|Right
|Code
_|Ctrl
_) ->
3889 vlog "huh? %s" (Wsi.keyname
key)
3892 let linknavkeyboard key mask
linknav =
3893 let pv = Wsi.kc2kt
key in
3894 let getpage pageno =
3895 let rec loop = function
3897 | l :: _ when l.pageno = pageno -> Some
l
3898 | _ :: rest
-> loop rest
3899 in loop state
.layout
3901 let doexact (pageno, n) =
3902 match getopaque pageno, getpage pageno with
3903 | Some
opaque, Some
l ->
3906 let under = getlink
opaque n in
3907 postRedisplay
"link gotounder";
3914 | Home
-> Some
(findlink
opaque LDfirst
), -1
3915 | End
-> Some
(findlink
opaque LDlast
), 1
3916 | Left
-> Some
(findlink
opaque (LDleft
n)), -1
3917 | Right
-> Some
(findlink
opaque (LDright
n)), 1
3918 | Up
-> Some
(findlink
opaque (LDup
n)), -1
3919 | Down
-> Some
(findlink
opaque (LDdown
n)), 1
3920 | Delete
|Escape
|Insert
|Enter
|Next
|Prior
|Ascii
_
3921 | Code
_|Fn
_|Ctrl
_|Backspace
-> None
, 0
3924 begin match findpwl
l.pageno dir with
3928 state
.mode <- LinkNav
(Ltgendir
dir);
3929 let y, h = getpageyh
pageno in
3932 then y + h - state
.winh
3937 begin match getopaque pageno, getpage pageno with
3938 | Some
opaque, Some
_ ->
3940 let ld = if dir > 0 then LDfirst
else LDlast
in
3943 begin match link with
3945 showlinktype (getlink
opaque m);
3946 state
.mode <- LinkNav
(Ltexact
(pageno, m));
3947 postRedisplay
"linknav jpage";
3948 | Lnotfound
-> notfound dir
3954 begin match opt with
3955 | Some Lnotfound
-> pwl l dir;
3956 | Some
(Lfound
m) ->
3960 let _, y0, _, y1 = getlinkrect
opaque m in
3962 then gotopage1 l.pageno y0
3964 let d = fstate
.fontsize
+ 1 in
3965 if y1 - l.pagey > l.pagevh - d
3966 then gotopage1 l.pageno (y1 - state
.winh
+ d)
3967 else postRedisplay
"linknav";
3969 showlinktype (getlink
opaque m);
3970 state
.mode <- LinkNav
(Ltexact
(l.pageno, m));
3973 | None
-> viewkeyboard key mask
3975 | _ -> viewkeyboard key mask
3979 begin match linknav with
3980 | Ltexact pa
-> state
.lnava
<- Some pa
3981 | Ltgendir
_ | Ltnotready
_ -> ()
3984 postRedisplay
"leave linknav"
3988 | Ltgendir
_ | Ltnotready
_ -> viewkeyboard key mask
3989 | Ltexact exact
-> doexact exact
3992 let keyboard key mask
=
3993 if (key = Char.code '
g'
&& Wsi.withctrl mask
) && not
(istextentry state
.mode)
3994 then wcmd "interrupt"
3995 else state
.uioh <- state
.uioh#
key key mask
3998 let birdseyekeyboard key mask
3999 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
4001 match conf
.columns
with
4003 | Cmulti
((c, _, _), _) -> c
4004 | Csplit
_ -> error
"bird's eye split mode"
4006 let pgh layout = List.fold_left
4007 (fun m l -> max
l.pageh
m) state
.winh
layout in
4009 match Wsi.kc2kt
key with
4010 | Ascii '
l'
when Wsi.withctrl mask
->
4011 let y, h = getpageyh
pageno in
4012 let top = (state
.winh
- h) / 2 in
4013 gotoxy state
.x (max
0 (y - top))
4014 | Enter
-> leavebirdseye beye
false
4015 | Escape
-> leavebirdseye beye
true
4016 | Up
-> upbirdseye incr beye
4017 | Down
-> downbirdseye incr beye
4018 | Left
-> upbirdseye 1 beye
4019 | Right
-> downbirdseye 1 beye
4022 begin match state
.layout with
4026 state
.mode <- Birdseye
(
4027 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4029 gotopage1 l.pageno 0;
4032 let layout = layout state
.x (state
.y-state
.winh
)
4034 (pgh state
.layout) in
4036 | [] -> gotoxy state
.x (clamp (-state
.winh
))
4038 state
.mode <- Birdseye
(
4039 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4041 gotopage1 l.pageno 0
4044 | [] -> gotoxy state
.x (clamp (-state
.winh
))
4048 begin match List.rev state
.layout with
4050 let layout = layout state
.x
4051 (state
.y + (pgh state
.layout))
4052 state
.winw state
.winh
in
4053 begin match layout with
4055 let incr = l.pageh
- l.pagevh in
4060 oconf
, leftx
, state
.pagecount
- 1, hooverpageno
, anchor
4062 postRedisplay
"birdseye pagedown";
4064 else gotoxy state
.x (clamp (incr + conf
.interpagespace
*2));
4068 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4069 gotopage1 l.pageno 0;
4072 | [] -> gotoxy state
.x (clamp state
.winh
)
4076 state
.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4080 let pageno = state
.pagecount
- 1 in
4081 state
.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4082 if not
(pagevisible state
.layout pageno)
4085 match List.rev state
.pdims
with
4087 | (_, _, h, _) :: _ -> h
4091 (max
0 (getpagey
pageno - (state
.winh
- h - conf
.interpagespace
)))
4092 else postRedisplay
"birdseye end";
4094 | Delete
|Insert
|Ascii
_|Code
_|Ctrl
_|Fn
_|Backspace
-> viewkeyboard key mask
4099 match state
.mode with
4100 | Textentry
_ -> scalecolor 0.4
4101 | LinkNav
_ | View
-> scalecolor 1.0
4102 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4103 if l.pageno = hooverpageno
4106 if l.pageno = pageno
4108 let c = scalecolor 1.0 in
4110 GlDraw.line_width
3.0;
4111 let dispx = l.pagedispx in
4113 (float (dispx-1)) (float (l.pagedispy-1))
4114 (float (dispx+l.pagevw+1))
4115 (float (l.pagedispy+l.pagevh+1));
4116 GlDraw.line_width
1.0;
4125 let postdrawpage l linkindexbase
=
4126 match getopaque l.pageno with
4128 if tileready l l.pagex
l.pagey
4130 let x = l.pagedispx - l.pagex
4131 and y = l.pagedispy - l.pagey in
4133 match conf
.columns
with
4134 | Csingle
_ | Cmulti
_ ->
4135 (if conf
.hlinks
then 1 else 0)
4137 && not
(isbirdseye state
.mode) then 2 else 0)
4141 match state
.mode with
4142 | Textentry
((_, s, _, _, _, _), _) when state
.glinks
-> s
4148 Hashtbl.find_all state
.prects
l.pageno |>
4149 List.iter
(fun vals
-> drawprect
opaque x y vals
);
4150 let n = postprocess
opaque hlmask x y (linkindexbase
, s, conf
.hfsize
) in
4152 then (Glutils.redisplay
:= true; 0)
4158 let scrollindicator () =
4159 let sbw, ph
, sh
= state
.uioh#scrollph
in
4160 let sbh, pw, sw
= state
.uioh#scrollpw
in
4165 else ((state
.winw
- sbw), state
.winw
, 0)
4169 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4170 let (r
, g, b, alpha
) = conf
.sbarcolor
in
4171 GlDraw.color (r
, g, b) ~alpha
;
4172 filledrect
(float x0) 0. (float x1) (float state
.winh
);
4174 (float hx0
) (float (state
.winh
- sbh))
4175 (float (hx0
+ state
.winw
)) (float state
.winh
);
4176 let (r
, g, b, alpha
) = conf
.sbarhndlcolor
in
4177 GlDraw.color (r
, g, b) ~alpha
;
4179 filledrect
(float x0) ph
(float x1) (ph
+. sh
);
4180 let pw = pw +. float hx0
in
4181 filledrect
pw (float (state
.winh
- sbh)) (pw +. sw
) (float state
.winh
);
4186 match state
.mstate
with
4187 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ -> ()
4188 | Msel
((x0, y0), (x1, y1)) ->
4189 let identify opaque l px py = Some
(opaque, l.pageno, px, py) in
4190 let o0,n0
,px0
,py0
= onppundermouse identify x0 y0 (~
< E.s, -1, 0, 0) in
4191 let _o1,n1
,px1
,py1
= onppundermouse identify x1 y1 (~
< E.s, -1, 0, 0) in
4192 if n0
!= -1 && n0
= n1
then seltext
o0 (px0
, py0
, px1
, py1
);
4195 let showrects = function
4199 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4200 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4202 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
4204 if l.pageno = pageno
4206 let dx = float (l.pagedispx - l.pagex
) in
4207 let dy = float (l.pagedispy - l.pagey) in
4208 let r, g, b, alpha
= c in
4209 GlDraw.color (r, g, b) ~alpha
;
4222 GlDraw.color (scalecolor2 conf
.bgcolor
);
4223 GlClear.color (scalecolor2 conf
.bgcolor
);
4224 GlClear.clear
[`
color];
4225 List.iter
drawpage state
.layout;
4227 match state
.mode with
4228 | LinkNav
(Ltexact
(pageno, linkno
)) ->
4229 begin match getopaque pageno with
4231 let x0, y0, x1, y1 = getlinkrect
opaque linkno
in
4232 let color = (0.0, 0.0, 0.5, 0.5) in
4234 (float x0, float y0,
4239 | None
-> state
.rects
4241 | LinkNav
(Ltgendir
_) | LinkNav
(Ltnotready
_)
4244 | View
-> state
.rects
4247 let rec postloop linkindexbase
= function
4249 let linkindexbase = linkindexbase + postdrawpage l linkindexbase in
4250 postloop linkindexbase rest
4254 postloop 0 state
.layout;
4256 begin match state
.mstate
with
4257 | Mzoomrect
((x0, y0), (x1, y1)) ->
4259 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4260 GlFunc.blend_func ~
src:`src_alpha ~dst
:`one_minus_src_alpha
;
4261 filledrect
(float x0) (float y0) (float x1) (float y1);
4265 | Mscrolly
| Mscrollx
4274 let zoomrect x y x1 y1 =
4277 and y0 = min
y y1 in
4278 let zoom = (float state
.w) /. float (x1 - x0) in
4281 if state
.w < state
.winw
4282 then (state
.winw
- state
.w) / 2
4285 match conf
.fitmodel
with
4286 | FitWidth
| FitProportional
-> simple ()
4288 match conf
.columns
with
4290 onppundermouse (fun _ l _ _ -> Some
l.pagedispx) x0 y0 x0
4291 | Cmulti
_ | Csingle
_ -> simple ()
4293 gotoxy ((state
.x + margin) - x0) (state
.y + y0);
4294 state
.anchor <- getanchor
();
4299 let annot inline
x y =
4300 match unproject x y with
4301 | Some
(opaque, n, ux
, uy
) ->
4303 addannot
opaque ux uy
text;
4304 wcmd "freepage %s" (~
> opaque);
4305 Hashtbl.remove state
.pagemap
(n, state
.gen
);
4307 gotoxy state
.x state
.y
4311 let ondone s = add s in
4312 let mode = state
.mode in
4313 state
.mode <- Textentry
(
4314 ("annotation: ", E.s, None
, textentry, ondone, true),
4315 fun _ -> state
.mode <- mode);
4318 postRedisplay
"annot"
4319 else add @@ getusertext E.s
4324 let g opaque l px py =
4325 match rectofblock
opaque px py with
4327 let x0 = a.(0) -. 20. in
4328 let x1 = a.(1) +. 20. in
4329 let y0 = a.(2) -. 20. in
4330 let zoom = (float state
.w) /. (x1 -. x0) in
4331 let pagey = getpagey
l.pageno in
4332 let margin = (state
.w - l.pagew
)/2 in
4333 let nx = -truncate
x0 - margin in
4334 gotoxy nx (pagey + truncate
y0);
4335 state
.anchor <- getanchor
();
4340 match conf
.columns
with
4342 impmsg "block zooming does not work properly in split columns mode"
4343 | Cmulti
_ | Csingle
_ -> onppundermouse g x y ()
4347 let winw = state
.winw - 1 in
4348 let s = float x /. float winw in
4349 let destx = truncate
(float (state
.w + winw) *. s) in
4350 gotoxy (winw - destx) state
.y;
4351 state
.mstate
<- Mscrollx
;
4355 let s = float y /. float state
.winh
in
4356 let desty = truncate
(s *. float (maxy ())) in
4357 gotoxy state
.x desty;
4358 state
.mstate
<- Mscrolly
;
4361 let viewmulticlick clicks
x y mask
=
4362 let g opaque l px py =
4370 if markunder
opaque px py mark
4374 match getopaque l.pageno with
4376 | Some
opaque -> pipesel opaque cmd
4378 state
.roam
<- (fun () -> dopipe conf
.paxcmd
);
4379 if not
(Wsi.withctrl mask
) then dopipe conf
.selcmd
;
4384 postRedisplay
"viewmulticlick";
4385 onppundermouse g x y (fun () -> impmsg "nothing to select") ();
4389 match conf
.columns
with
4391 | Csingle
_ | Cmulti
_ -> conf
.angle
mod 360 = 0
4394 let viewmouse button down
x y mask
=
4396 | n when (n == 4 || n == 5) && not down
->
4397 if Wsi.withctrl mask
4401 then if conf
.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4402 else if conf
.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4405 match state
.mstate
with
4406 | Mzoom
(oldn
, _, pos
) when n = oldn
-> pos
4407 | Mzoomrect
_ | Mnone
| Mpan
_
4408 | Msel
_ | Mscrollx
| Mscrolly
| Mzoom
_ -> (x, y)
4410 let zoom = conf
.zoom -. incr in
4411 state
.mstate
<- Mzoom
(n, 0, (x, y));
4412 if false && abs
(fx - x) > 5 || abs
(fy
- y) > 5
4413 then pivotzoom ~
x ~
y zoom
4417 match state
.autoscroll
with
4418 | Some step
-> setautoscrollspeed step
(n=4)
4420 if conf
.wheelbypage
|| conf
.presentation
4427 let incr = if n = 4 then -conf
.scrollstep
else conf
.scrollstep
in
4428 let incr = incr * 2 in
4429 let y = clamp incr in
4433 | n when (n = 6 || n = 7) && not down
&& canpan () ->
4435 panbound (state
.x + (if n = 7 then -2 else 2) * conf
.hscrollstep
) in
4438 | 1 when Wsi.withshift mask
->
4439 state
.mstate
<- Mnone
;
4442 match unproject x y with
4444 | Some
(_, pageno, ux
, uy
) ->
4445 let cmd = Printf.sprintf
4447 conf
.stcmd state
.path pageno ux uy
4449 match spawn
cmd [] with
4451 impmsg "execution of synctex command(%S) failed: %S"
4452 conf
.stcmd
@@ exntos exn
4456 | 1 when Wsi.withctrl mask
->
4459 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
4460 state
.mstate
<- Mpan
(x, y)
4462 else state
.mstate
<- Mnone
4467 if Wsi.withshift mask
4469 annot conf
.annotinline
x y;
4470 postRedisplay
"addannot"
4474 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
4475 state
.mstate
<- Mzoomrect
(p, p)
4478 match state
.mstate
with
4479 | Mzoomrect
((x0, y0), _) ->
4480 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4481 then zoomrect x0 y0 x y
4484 postRedisplay
"kill accidental zoom rect";
4488 | Mscrolly
| Mscrollx
4490 | Mnone
-> resetmstate ()
4493 | 1 when vscrollhit
x ->
4496 let _, position
, sh
= state
.uioh#scrollph
in
4497 if y > truncate position
&& y < truncate
(position
+. sh
)
4498 then state
.mstate
<- Mscrolly
4500 else state
.mstate
<- Mnone
4502 | 1 when y > state
.winh
- hscrollh () ->
4505 let _, position
, sw
= state
.uioh#scrollpw
in
4506 if x > truncate position
&& x < truncate
(position
+. sw
)
4507 then state
.mstate
<- Mscrollx
4509 else state
.mstate
<- Mnone
4511 | 1 when state
.bzoom
-> if not down
then zoomblock x y
4514 let dest = if down
then getunder x y else Unone
in
4515 begin match dest with
4516 | Ulinkuri
_ -> gotounder dest
4517 | Unone
when down
->
4518 Wsi.setcursor
Wsi.CURSOR_FLEUR
;
4519 state
.mstate
<- Mpan
(x, y);
4520 | Uannotation
(opaque, slinkindex
) -> enterannotmode opaque slinkindex
4521 | Unone
| Utext
_ ->
4526 state
.mstate
<- Msel
((x, y), (x, y));
4527 postRedisplay
"mouse select";
4531 match state
.mstate
with
4533 | Mzoom
_ | Mscrollx
| Mscrolly
-> state
.mstate
<- Mnone
4534 | Mzoomrect
((x0, y0), _) -> zoomrect x0 y0 x y
4536 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4537 state
.mstate
<- Mnone
4538 | Msel
((x0, y0), (x1, y1)) ->
4539 let rec loop = function
4543 let a0 = l.pagedispy in
4544 let a1 = a0 + l.pagevh in
4545 let b0 = l.pagedispx in
4546 let b1 = b0 + l.pagevw in
4547 ((y0 >= a0 && y0 <= a1) || (y1 >= a0 && y1 <= a1))
4548 && ((x0 >= b0 && x0 <= b1) || (x1 >= b0 && x1 <= b1))
4552 match getopaque l.pageno with
4555 pipef ~closew
:false "Msel"
4558 postRedisplay
"Msel") cmd
4560 dosel conf
.selcmd
();
4561 state
.roam
<- dosel conf
.paxcmd
;
4572 let birdseyemouse button down
x y mask
4573 (conf
, leftx
, _, hooverpageno
, anchor) =
4576 let rec loop = function
4579 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4580 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4582 leavebirdseye (conf
, leftx
, l.pageno, hooverpageno
, anchor) false;
4588 | _ -> viewmouse button down
x y mask
4594 method key key mask
=
4595 begin match state
.mode with
4596 | Textentry
textentry -> textentrykeyboard
key mask
textentry
4597 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
4598 | View
-> viewkeyboard key mask
4599 | LinkNav
linknav -> linknavkeyboard key mask
linknav
4603 method button button bstate
x y mask
=
4604 begin match state
.mode with
4605 | LinkNav
_ | View
-> viewmouse button bstate
x y mask
4606 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
4611 method multiclick clicks
x y mask
=
4612 begin match state
.mode with
4613 | LinkNav
_ | View
-> viewmulticlick clicks
x y mask
4614 | Birdseye
_ | Textentry
_ -> ()
4619 begin match state
.mode with
4621 | View
| Birdseye
_ | LinkNav
_ ->
4622 match state
.mstate
with
4623 | Mzoom
_ | Mnone
-> ()
4627 state
.mstate
<- Mpan
(x, y);
4628 let x = if canpan () then panbound (state
.x + dx) else state
.x in
4633 state
.mstate
<- Msel
(a, (x, y));
4634 postRedisplay
"motion select";
4637 let y = min state
.winh
(max
0 y) in
4641 let x = min state
.winw (max
0 x) in
4644 | Mzoomrect
(p0
, _) ->
4645 state
.mstate
<- Mzoomrect
(p0
, (x, y));
4646 postRedisplay
"motion zoomrect";
4650 method pmotion
x y =
4651 begin match state
.mode with
4652 | Birdseye
(conf
, leftx
, pageno, hooverpageno
, anchor) ->
4653 let rec loop = function
4655 if hooverpageno
!= -1
4657 state
.mode <- Birdseye
(conf
, leftx
, pageno, -1, anchor);
4658 postRedisplay
"pmotion birdseye no hoover";
4661 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4662 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4664 state
.mode <- Birdseye
(conf
, leftx
, pageno, l.pageno, anchor);
4665 postRedisplay
"pmotion birdseye hoover";
4673 | LinkNav
_ | View
->
4674 match state
.mstate
with
4675 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ -> ()
4684 let delta = now -. past
in
4687 else conf
.pax
<- Some
now
4691 method infochanged
_ = ()
4694 let maxy = maxy () in
4697 then 0.0, float state
.winh
4698 else scrollph state
.y maxy
4703 let fwinw = float (state
.winw - vscrollw
()) in
4705 let sw = fwinw /. float state
.w in
4706 let sw = fwinw *. sw in
4707 max
sw (float conf
.scrollh
)
4710 let maxx = state
.w + state
.winw in
4711 let x = state
.winw - state
.x in
4712 let percent = float x /. float maxx in
4713 (fwinw -. sw) *. percent
4715 hscrollh (), position, sw
4719 match state
.mode with
4720 | LinkNav
_ -> "links"
4721 | Textentry
_ -> "textentry"
4722 | Birdseye
_ -> "birdseye"
4725 findkeyhash conf
modename
4727 method eformsgs
= true
4728 method alwaysscrolly
= false
4729 method scroll
dx dy =
4730 let x = if canpan () then panbound (state
.x + dx) else state
.x in
4731 gotoxy x (clamp (2 * dy));
4734 pivotzoom ~
x ~
y (conf
.zoom *. exp z
);
4737 let addrect pageno r g b a x0 y0 x1 y1 =
4738 Hashtbl.add state
.prects
pageno [|r; g; b; a; x0; y0; x1; y1|];
4742 let cl = splitatchar cmds ' '
in
4744 try Scanf.sscanf
s fmt
f
4745 with exn
-> adderrfmt "remote exec" "error processing '%S': %s\n"
4748 let rectx s pageno (r, g, b, a) x0 y0 x1 y1 =
4749 vlog "%s page %d color (%f %f %f %f) x0,y0,x1,y1 = %f %f %f %f"
4750 s pageno r g b a x0 y0 x1 y1;
4754 let _,w1
,h1
,_ = getpagedim
pageno in
4755 let sw = float w1
/. float w
4756 and sh
= float h1
/. float h in
4760 and y1s
= y1 *. sh
in
4761 let rect = (x0s,y0s
,x1s
,y0s
,x1s
,y1s
,x0s,y1s
) in
4762 let color = (r, g, b, a) in
4763 if conf
.verbose
then debugrect rect;
4764 state
.rects <- (pageno, color, rect) :: state
.rects;
4769 | "reload", "" -> reload ()
4771 scan args
"%u %f %f"
4773 let cmd, _ = state
.geomcmds
in
4775 then gotopagexy pageno x y
4778 gotopagexy pageno x y;
4781 state
.reprf
<- f state
.reprf
4783 | "goto1", args
-> scan args
"%u %f" gotopage
4784 | "gotor", args
-> scan args
"%S" gotoremote
4786 scan args
"%u %u %f %f %f %f"
4787 (fun pageno c x0 y0 x1 y1 ->
4788 let color = (0.0, 0.0, 1.0 /. float c, 0.5) in
4789 rectx "rect" pageno color x0 y0 x1 y1;
4792 scan args
"%u %f %f %f %f %f %f %f %f"
4793 (fun pageno r g b alpha
x0 y0 x1 y1 ->
4794 addrect pageno r g b alpha
x0 y0 x1 y1;
4795 postRedisplay
"prect"
4798 scan args
"%u %f %f"
4801 match getopaque pageno with
4802 | Some
opaque -> opaque
4805 pgoto optopaque pageno x y;
4806 let rec fixx = function
4809 if l.pageno = pageno
4810 then gotoxy (state
.x - l.pagedispx) state
.y
4815 match conf
.columns
with
4816 | Csingle
_ | Csplit
_ -> 1
4817 | Cmulti
((n, _, _), _) -> n
4819 layout 0 state
.y (state
.winw * mult) state
.winh
4823 | "activatewin", "" -> Wsi.activatewin
()
4824 | "quit", "" -> raise Quit
4827 let l = Config.keys_of_string
keys in
4828 List.iter
(fun (k
, m) -> keyboard k
m) l
4829 with exn
-> adderrfmt "error processing keys" "`%S': %s\n"
4832 | "clearrects", "" ->
4833 Hashtbl.clear state
.prects
;
4834 postRedisplay
"clearrects"
4836 adderrfmt "remote command"
4837 "error processing remote command: %S\n" cmds
;
4841 let scratch = Bytes.create
80 in
4842 let buf = Buffer.create
80 in
4844 match tempfailureretry
(Unix.read fd
scratch 0) 80 with
4845 | exception Unix.Unix_error
(Unix.EAGAIN
, _, _) -> None
4848 if Buffer.length
buf > 0
4850 let s = Buffer.contents
buf in
4858 match Bytes.index_from
scratch ppos '
\n'
with
4859 | pos
-> if pos
>= n then -1 else pos
4860 | exception Not_found
-> -1
4864 Buffer.add_subbytes
buf scratch ppos
(nlpos-ppos
);
4865 let s = Buffer.contents
buf in
4871 Buffer.add_subbytes
buf scratch ppos
(n-ppos
);
4877 let remoteopen path =
4878 try Some
(Unix.openfile
path [Unix.O_NONBLOCK
; Unix.O_RDONLY
] 0o0)
4880 adderrfmt "remoteopen" "error opening %S: %s" path @@ exntos exn
;
4885 let gcconfig = ref false in
4886 let trimcachepath = ref E.s in
4887 let rcmdpath = ref E.s in
4888 let pageno = ref None
in
4889 let openlast = ref false in
4890 let doreap = ref false in
4891 let csspath = ref None
in
4892 selfexec := Sys.executable_name
;
4895 [("-p", Arg.String
(fun s -> state
.password <- s),
4896 "<password> Set password");
4900 Config.fontpath
:= s;
4901 selfexec := !selfexec ^
" -f " ^
Filename.quote
s;
4903 "<path> Set path to the user interface font");
4907 selfexec := !selfexec ^
" -c " ^
Filename.quote
s;
4908 Config.confpath
:= s),
4909 "<path> Set path to the configuration file");
4911 ("-last", Arg.Set
openlast, " Open last document");
4913 ("-page", Arg.Int
(fun pageno1
-> pageno := Some
(pageno1
-1)),
4914 "<page-number> Jump to page");
4916 ("-tcf", Arg.String
(fun s -> trimcachepath := s),
4917 "<path> Set path to the trim cache file");
4919 ("-dest", Arg.String
(fun s -> state
.nameddest
<- s),
4920 "<named-destination> Set named destination");
4922 ("-remote", Arg.String
(fun s -> rcmdpath := s),
4923 "<path> Set path to the source of remote commands");
4925 ("-gc", Arg.Set
gcconfig, " Collect config garbage");
4927 ("-v", Arg.Unit
(fun () ->
4929 "%s\nconfiguration file: %s\n"
4932 exit
0), " Print version and exit");
4934 ("-css", Arg.String
(fun s -> csspath := Some
s),
4935 "<path> Set path to the style sheet to use with EPUB/HTML");
4937 ("-origin", Arg.String
(fun s -> state
.origin
<- s),
4938 "<origin> <undocumented>");
4940 ("-no-title", Arg.Set
ignoredoctitlte, " ignore document title");
4941 ("-layout-height", Arg.Set_int
layouth,
4942 "<height> layout height html/epub/etc (-1, 0, N)");
4945 (fun s -> state
.path <- s)
4946 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:");
4948 let histmode = emptystr state
.path && not
!openlast in
4950 if not
(Config.load !openlast)
4951 then dolog
"failed to load configuration";
4953 begin match !pageno with
4954 | Some
pageno -> state
.anchor <- (pageno, 0.0, 0.0)
4967 val mutable m_clicks
= 0
4968 val mutable m_click_x
= 0
4969 val mutable m_click_y
= 0
4970 val mutable m_lastclicktime
= infinity
4972 method private cleanup =
4973 state
.roam
<- noroam
;
4974 Hashtbl.iter
(fun _ opaque -> clearmark
opaque) state
.pagemap
4975 method expose
= postRedisplay
"expose"
4979 | Wsi.Unobscured
-> "unobscured"
4980 | Wsi.PartiallyObscured
-> "partiallyobscured"
4981 | Wsi.FullyObscured
-> "fullyobscured"
4983 vlog "visibility change %s" name
4984 method display = display ()
4985 method map mapped
= vlog "mapped %b" mapped
4986 method reshape w h =
4989 method mouse
b d x y m =
4990 if d && canselect ()
4993 * http://blogs.msdn.com/b/oldnewthing/archive/2004/10/18/243925.aspx
5000 if abs
x - m_click_x
> 10
5001 || abs
y - m_click_y
> 10
5002 || abs_float
(t -. m_lastclicktime
) > 0.3
5004 m_clicks
<- m_clicks
+ 1;
5005 m_lastclicktime
<- t;
5009 postRedisplay
"cleanup";
5010 state
.uioh <- state
.uioh#button
b d x y m;
5012 else state
.uioh <- state
.uioh#multiclick m_clicks
x y m
5017 m_lastclicktime
<- infinity
;
5018 state
.uioh <- state
.uioh#button
b d x y m
5021 else state
.uioh <- state
.uioh#button
b d x y m
5023 state
.mpos
<- (x, y);
5024 state
.uioh <- state
.uioh#motion
x y
5025 method pmotion
x y =
5026 state
.mpos
<- (x, y);
5027 state
.uioh <- state
.uioh#pmotion
x y
5029 vlog "k=%#x m=%#x" k
m;
5030 let mascm = m land (
5031 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
5034 let x = state
.x and y = state
.y in
5036 if x != state
.x || y != state
.y then self#
cleanup
5038 match state
.keystate
with
5040 let km = k
, mascm in
5043 let modehash = state
.uioh#
modehash in
5044 try Hashtbl.find
modehash km
5046 try Hashtbl.find
(findkeyhash conf
"global") km
5047 with Not_found
-> KMinsrt
(k
, m)
5049 | KMinsrt
(k
, m) -> keyboard k
m
5050 | KMinsrl
l -> List.iter
(fun (k
, m) -> keyboard k
m) l
5051 | KMmulti
(l, r) -> state
.keystate
<- KSinto
(l, r)
5053 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k
&& m'
land mascm = m'
->
5054 List.iter
(fun (k
, m) -> keyboard k
m) insrt
;
5055 state
.keystate
<- KSnone
5056 | KSinto
((k'
, m'
) :: keys, insrt
) when k'
=k
&& m'
land mascm = m'
->
5057 state
.keystate
<- KSinto
(keys, insrt
)
5058 | KSinto
_ -> state
.keystate
<- KSnone
5061 state
.mpos
<- (x, y);
5062 state
.uioh <- state
.uioh#pmotion
x y
5063 method leave = state
.mpos
<- (-1, -1)
5064 method winstate wsl
= state
.winstate
<- wsl
5065 method quit
: '
a. '
a = raise Quit
5066 method scroll
dx dy = state
.uioh <- state
.uioh#scroll
dx dy
5067 method zoom z
x y = state
.uioh#
zoom z
x y
5068 method opendoc path =
5071 postRedisplay
"opendoc";
5072 opendoc path state
.password
5075 let wsfd, winw, winh
= Wsi.init
mu conf
.cwinw conf
.cwinh platform
in
5078 if not
@@ List.exists
GlMisc.check_extension
5079 [ "GL_ARB_texture_rectangle"
5080 ; "GL_EXT_texture_recangle"
5081 ; "GL_NV_texture_rectangle" ]
5082 then (dolog
"OpenGL does not suppport rectangular textures"; exit
1);
5084 if substratis
(GlMisc.get_string `renderer
) 0 "Mesa DRI Intel("
5086 defconf
.sliceheight
<- 1024;
5087 defconf
.texcount
<- 32;
5088 defconf
.usepbo
<- true;
5092 match Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0 with
5094 dolog
"socketpair failed: %s" @@ exntos exn
;
5102 setcheckers conf
.checkers
;
5104 opengl_has_pbo := GlMisc.check_extension
"GL_ARB_pixel_buffer_object";
5106 begin match !csspath with
5108 | Some
"" -> conf
.css
<- E.s
5110 let css = filecontents
path in
5111 let l = String.length
css in
5113 if substratis
css (l-2) "\r\n"
5114 then String.sub css 0 (l-2)
5115 else (if css.[l-1] = '
\n'
then String.sub css 0 (l-1) else css)
5118 conf
.angle
, conf
.fitmodel
, (conf
.trimmargins
, conf
.trimfuzz
),
5119 conf
.texcount
, conf
.sliceheight
, conf
.mustoresize
, conf
.colorspace
,
5120 !Config.fontpath
, !trimcachepath, !opengl_has_pbo
5122 List.iter
GlArray.enable
[`texture_coord
; `vertex
];
5124 reshape ~firsttime
:true winw winh
;
5128 Wsi.settitle
"llpp (history)";
5132 state
.text <- "Opening " ^
(mbtoutf8 state
.path);
5133 opendoc state
.path state
.password;
5137 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5138 Sys.set_signal
Sys.sighup
(Sys.Signal_handle
(fun _ -> reload ()));
5141 match Unix.waitpid
[Unix.WNOHANG
] ~
-1 with
5142 | exception (Unix.Unix_error
(Unix.ECHILD
, _, _)) -> ()
5143 | exception exn
-> dolog
"Unix.waitpid: %s" @@ exntos exn
5145 | _pid
, _status
-> reap ()
5147 Sys.set_signal
Sys.sigchld
(Sys.Signal_handle
(fun _ -> doreap := true));
5150 ref (if nonemptystr
!rcmdpath then remoteopen !rcmdpath else None
)
5153 let rec loop deadline
=
5159 let r = [state
.ss; state
.wsfd] in
5163 | Some fd
-> fd
:: r
5167 Glutils.redisplay
:= false;
5174 if deadline
= infinity
5176 else max
0.0 (deadline
-. now)
5181 try Unix.select
r [] [] timeout
5182 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
5187 match state
.autoscroll
with
5188 | Some step
when step
!= 0 ->
5189 if state
.slideshow
land 1 = 1
5191 if state
.slideshow
land 2 = 0
5192 then state
.slideshow
<- state
.slideshow
lor 2
5193 else if step
< 0 then prevpage () else nextpage ();
5194 deadline
+. (float (abs step
))
5197 let y = state
.y + step
in
5198 let fy = if conf
.maxhfit
then state
.winh
else 0 in
5201 then state
.maxy - fy
5202 else if y >= state
.maxy - fy then 0 else y
5211 let rec checkfds = function
5213 | fd
:: rest
when fd
= state
.ss ->
5214 let cmd = rcmd state
.ss in
5218 | fd
:: rest
when fd
= state
.wsfd ->
5222 | fd
:: rest
when Some fd
= !optrfd ->
5223 begin match remote fd
with
5224 | None
-> optrfd := remoteopen !rcmdpath;
5225 | opt -> optrfd := opt
5230 dolog
"select returned unknown descriptor";
5236 if deadline
= infinity
5240 match state
.autoscroll
with
5241 | Some step
when step
!= 0 -> deadline1
5247 match loop infinity
with
5249 Config.save leavebirdseye;
5250 if hasunsavedchanges
()
5252 | _ -> error
"umpossible - infinity reached"