4 { mutable fontsize
: int
5 ; mutable wwidth
: float
6 ; mutable maxrows
: int
11 { fontsize
= 20 * Wsi.fontsizefactor
()
17 let irect_of_string s
=
18 Scanf.sscanf s
"%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0
,y0
,x1
,y1
))
21 let irect_to_string (x0
,y0
,x1
,y1
) =
22 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
25 let multicolumns_to_string (n
, a
, b
) =
27 then Printf.sprintf
"%d" n
28 else Printf.sprintf
"%d,%d,%d" n a b
;
31 let multicolumns_of_string s
=
33 (int_of_string s
, 0, 0)
35 Scanf.sscanf s
"%u,%u,%u" (fun n a b
->
37 then failwith
"subtly broken";
45 (angle
* fitmodel
* trimparams
* texcount
* sliceheight
* memsize
46 * colorspace
* fontpath
* trimcachepath
* haspbo
)
55 and trimcachepath
= string
57 and trimmargins
= bool
58 and trimparams
= (trimmargins
* irect
)
60 and usefontconfig
= bool
66 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
71 | Uannotation
of (opaque
* slinkindex
)
74 and launchcommand
= string
84 | LDfirstvisible
of (int * int * int)
93 and anchor
= pageno
* top
* dtop
94 and rect
= float * float * float * float * float * float * float * float
95 and infochange
= | Memused
| Docinfo
| Pdim
100 method display
: unit
101 method key
: int -> int -> uioh
102 method button
: int -> bool -> int -> int -> int -> uioh
103 method multiclick
: int -> int -> int -> int -> uioh
104 method motion
: int -> int -> uioh
105 method pmotion
: int -> int -> uioh
106 method infochanged
: infochange
-> unit
107 method scrollpw
: (int * float * float)
108 method scrollph
: (int * float * float)
109 method modehash
: keyhash
110 method eformsgs
: bool
111 method alwaysscrolly
: bool
112 method scroll
: int -> int -> uioh
113 method zoom
: float -> int -> int -> unit
116 module type TextEnumType
=
120 val names
: string array
123 module TextEnumMake
(Ten
: TextEnumType
) =
125 let names = Ten.names;;
126 let to_int (t
: Ten.t
) = Obj.magic t
;;
127 let to_string t
= names.(to_int t
);;
128 let of_int n
: Ten.t
= Obj.magic n
;;
131 if i
= Array.length
names
132 then failwith
("invalid " ^
Ten.name ^
": " ^ s
)
141 module CSTE
= TextEnumMake
(struct
142 type t
= colorspace
;;
143 let name = "colorspace";;
144 let names = [|"rgb"; "bgr"; "gray"|];;
147 module MTE
= TextEnumMake
(struct
150 let names = [|"page"; "block"; "line"; "word"|];;
153 module FMTE
= TextEnumMake
(struct
155 let name = "fitmodel";;
156 let names = [|"width"; "proportional"; "page"|];;
163 | Olaunch
of launchcommand
164 | Oremote
of (filename
* pageno
)
165 | Oremotedest
of (filename
* destname
)
166 | Ohistory
of (filename
* conf
* outline list
* x
* anchor
* filename
)
167 and outline
= (caption
* outlinelevel
* outlinekind
)
168 and outlinelevel
= int
186 type tile
= opaque
* pixmapsize
* elapsed
187 and elapsed
= float;;
188 type pagemapkey
= pageno
* gen
;;
189 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
194 | Loading
of (page
* gen
)
196 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
198 | Outlining
of outline list
201 type mpos
= int * int
203 | Msel
of (mpos
* mpos
)
205 | Mscrolly
| Mscrollx
206 | Mzoom
of (buttonno
* step
* mpos
)
207 | Mzoomrect
of (mpos
* mpos
)
214 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
215 | Textentry
of (textentry
* onleave
)
217 | LinkNav
of linktarget
218 and onleave
= leavetextentrystatus
-> unit
219 and leavetextentrystatus
= | Cancel
| Confirm
220 and helpitem
= string * int * action
223 | Action
of (uioh
-> uioh
)
225 | Ltexact
of (pageno
* direction
)
226 | Ltgendir
of direction
227 | Ltnotready
of (pageno
* direction
)
228 and direction
= int (* -1, 0, 1 *)
229 and textentry
= string * string * onhist
option
230 * onkey
* ondone
* cancelonempty
231 and onkey
= string -> Keys.t
-> te
232 and ondone
= string -> unit
233 and histcancel
= unit -> unit
234 and onhist
= ((histcmd
-> string) * histcancel
)
235 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
236 and cancelonempty
= bool
241 | TEswitch
of textentry
253 { mutable ss
: Unix.file_descr
254 ; mutable wsfd
: Unix.file_descr
255 ; mutable stderr
: Unix.file_descr
256 ; mutable errmsgs
: Buffer.t
257 ; mutable newerrmsgs
: bool
261 ; mutable anchor
: anchor
262 ; mutable ranchors
: (string * string * anchor
* string) list
264 ; mutable layout
: page list
265 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
266 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
267 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
268 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
269 ; mutable pagecount
: int
270 ; mutable currently
: currently
271 ; mutable mstate
: mstate
272 ; mutable searchpattern
: string
273 ; mutable rects
: (pageno
* rectcolor
* rect
) list
274 ; mutable rects1
: (pageno
* rectcolor
* rect
) list
275 ; prects
: (pageno
, float array
) Hashtbl.t
276 ; mutable text
: string
277 ; mutable winstate
: Wsi.winstate list
278 ; mutable mode
: mode
279 ; mutable uioh
: uioh
280 ; mutable outlines
: outline array
281 ; mutable bookmarks
: outline list
282 ; mutable path
: string
283 ; mutable password
: string
284 ; mutable nameddest
: string
285 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
286 ; mutable memused
: memsize
288 ; mutable autoscroll
: int option
289 ; mutable help
: helpitem array
290 ; mutable docinfo
: (int * string) list
291 ; mutable checkerstexid
: GlTex.texture_id
option
293 ; mutable prevzoom
: (float * int)
294 ; mutable progress
: float
295 ; mutable mpos
: mpos
296 ; mutable keystate
: keystate
297 ; mutable glinks
: bool
298 ; mutable prevcolumns
: (columns
* float) option
301 ; mutable reprf
: (unit -> unit)
302 ; mutable origin
: string
303 ; mutable roam
: (unit -> unit)
304 ; mutable bzoom
: bool
305 ; mutable lnava
: (pageno
* linkno
) option
306 ; mutable slideshow
: int
309 { pat
: string circbuf
310 ; pag
: string circbuf
311 ; nav
: anchor circbuf
312 ; sel
: string circbuf
316 let emptyanchor = (0, 0.0, 0.0);;
317 let emptykeyhash = Hashtbl.create
0;;
318 let noreprf () = ();;
321 let nouioh : uioh
= object (self
)
323 method key _ _
= self
324 method multiclick _ _ _ _
= self
325 method button _ _ _ _ _
= self
326 method motion _ _
= self
327 method pmotion _ _
= self
328 method infochanged _
= ()
329 method scrollpw
= (0, nan
, nan
)
330 method scrollph
= (0, nan
, nan
)
331 method modehash
= emptykeyhash
332 method eformsgs
= false
333 method alwaysscrolly
= false
334 method scroll _ _
= self
335 method zoom _ _ _
= ()
338 let platform_to_string = function
339 | Punknown
-> "unknown"
346 let conf = { defconf
with keyhashes
= copykeyhashes defconf
};;
349 { store
= Array.make n v
356 let cbcap b
= Array.length b
.store
;;
358 let cbput ?
(update_rc
=true) b v
=
361 b
.wc
<- (b
.wc
+ 1) mod cap;
364 b
.len
<- min
(b
.len
+ 1) cap;
367 let cbput_dont_update_rc b v
= cbput ~update_rc
:false b v
;;
369 let cbempty b
= b
.len
= 0;;
371 let cbgetg b circular dir
=
375 let rc = b
.rc + dir
in
387 else bound
rc 0 (b
.len
-1)
393 let cbget b
= cbgetg b
false;;
394 let cbgetc b
= cbgetg b
true;;
399 ; stderr
= Unix.stderr
400 ; errmsgs
= Buffer.create
0
405 ; anchor
= emptyanchor
409 ; tilelru
= Queue.create
()
410 ; pagemap
= Hashtbl.create
10
411 ; tilemap
= Hashtbl.create
10
418 ; prects
= Hashtbl.create
1
422 ; searchpattern
= E.s
430 { nav
= cbnew 10 emptyanchor
440 ; checkerstexid
= None
441 ; prevzoom
= (1.0, 0)
460 let d = state.winh
- h
in
461 max
conf.interpagespace
((d + 1) / 2)
464 let rowyh (c
, coverA
, coverB
) b n
=
465 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
467 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
470 let n'
= n - coverA
in
473 let e = min
state.pagecount
(s + c
) in
474 let rec find m miny maxh
= if m
= e then miny
, maxh
else
475 let _, _, y
, (_, _, h
, _) = b
.(m
) in
476 let miny = min
miny y
in
477 let maxh = max
maxh h
in
483 let ((c
, coverA
, coverB
) as cl
), b
=
484 match conf.columns
with
485 | Csplit
(_, b
) | Csingle b
-> (1, 0, 0), b
486 | Cmulti
(c
, b
) -> c
, b
488 if Array.length b
= 0
491 let rec bsearch nmin nmax
=
493 then bound nmin
0 (state.pagecount
-1)
495 let n = (nmax
+ nmin
) / 2 in
496 let vy, h
= rowyh cl b
n in
500 let ips = calcips h
in
502 let y1 = vy + h
+ ips in
506 then 0, vy + h
+ conf.interpagespace
508 let y0 = vy - conf.interpagespace
in
509 y0, y0 + h
+ conf.interpagespace
519 if n < state.pagecount
- coverB
520 then ((n-coverA
)/c
)*c
+ coverA
527 then bsearch (n+1) nmax
528 else bsearch nmin
(n-1)
531 bsearch 0 (state.pagecount
-1);
535 match conf.columns
with
536 | Cmulti
((_, _, _) as cl
, b
) ->
537 if Array.length b
> 0
539 let y, h
= rowyh cl b
(Array.length b
- 1) in
540 y + h
+ (if conf.presentation
then calcips h
else 0)
543 if Array.length b
> 0
545 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
546 y + h
+ (if conf.presentation
then calcips h
else 0)
549 if Array.length b
> 0
551 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
556 let getpageywh pageno
=
557 let pageno = bound
pageno 0 (state.pagecount
-1) in
558 match conf.columns
with
560 if Array.length b
= 0
563 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
571 if Array.length b
= 0
574 let y, h
= rowyh cl b
pageno in
575 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
583 if Array.length b
= 0
587 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
591 let getpageyh pageno =
592 let y,_,h
= getpageywh pageno in
596 let getpagedim pageno =
599 | (n, _, _, _) as pdim
:: rest
->
601 then (if n = pageno then pdim
else ppdim
)
606 f (-1, -1, -1, -1) state.pdims
609 let getpdimno pageno =
613 | (n, _, _, _) :: rest
->
615 then (if n = pageno then np else p
)
623 let getpagey pageno = fst
(getpageyh pageno);;
627 let coloff = l
.pagecol
* l
.pageh
in
628 float (l
.pagey
+ coloff) /. float l
.pageh
636 then float l
.pagedispy
/. float (calcips l
.pageh
)
637 else float l
.pagedispy
/. float conf.interpagespace
640 (l
.pageno, top, dtop)
644 match state.layout
with
645 | l
:: _ -> getanchor1 l
647 let n = page_of_y state.y in
651 let y, h
= getpageyh n in
652 let dy = y - state.y in
656 let ips = calcips h
in
657 float (dy + ips) /. float ips
659 float dy /. float conf.interpagespace
664 let fontpath = ref E.s;;
666 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
669 Map.Make
(struct type t
= (int * int) let compare = compare end);;
672 let l = String.length
s in
673 let b = Buffer.create
l in
674 Parser.unent
b s 0 l;
679 try Sys.getenv
"HOME"
681 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
685 let modifier_of_string = function
686 | "alt" -> Wsi.altmask
687 | "shift" -> Wsi.shiftmask
688 | "ctrl" | "control" -> Wsi.ctrlmask
689 | "meta" -> Wsi.metamask
693 let keys_of_string s =
694 let key_of_string r
s =
695 let elems = Str.full_split r
s in
698 let m1 = modifier_of_string s in
700 then (Wsi.namekey
s, m
)
703 | Str.Delim
s when n land 1 = 0 -> g s
705 | Str.Delim
_ -> (k
, m
)
707 let rec loop n k m
= function
710 let k, m
= f n k m x
in
715 let elems = Str.split whitere
s in
716 List.map
(key_of_string (Str.regexp
"-")) elems
719 let config_of c attrs
=
723 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
724 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
725 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
726 | "preload" -> { c
with preload
= bool_of_string v
}
727 | "page-bias" -> { c
with pagebias
= int_of_string v
}
728 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
729 | "horizontal-scroll-step" ->
730 { c
with hscrollstep
= max
(int_of_string v
) 1 }
731 | "auto-scroll-step" ->
732 { c
with autoscrollstep
= max
0 (int_of_string v
) }
733 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
734 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
735 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
736 | "vertical-margin" ->
737 { c
with interpagespace
= max
0 (int_of_string v
) }
739 let zoom = float_of_string v
/. 100. in
740 let zoom = max
zoom 0.0 in
741 { c
with zoom = zoom }
742 | "presentation" -> { c
with presentation
= bool_of_string v
}
743 | "rotation-angle" -> { c
with angle
= int_of_string v
}
744 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
745 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
746 | "proportional-display" ->
752 { c
with fitmodel
= fm }
753 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
754 | "pixmap-cache-size" ->
755 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
756 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
757 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
758 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
759 | "background-color" -> { c
with bgcolor
= color_of_string v
}
760 | "scrollbar-color" -> { c
with sbarcolor
= rgba_of_string v
}
761 | "scrollbar-handle-color" -> { c
with sbarhndlcolor
= rgba_of_string v
}
762 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
763 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
764 | "mupdf-store-size" ->
765 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
766 | "checkers" -> { c
with checkers
= bool_of_string v
}
767 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
768 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
769 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
770 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
771 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
772 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
773 | "invert-colors" -> { c
with invert
= bool_of_string v
}
774 | "brightness" -> { c
with colorscale
= float_of_string v
}
776 let (n, _, _) as nab
= multicolumns_of_string v
in
778 then { c
with columns
= Csplit
(-n, E.a
) }
779 else { c
with columns
= Cmulti
(nab
, E.a
) }
780 | "birds-eye-columns" ->
781 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
782 | "selection-command" -> { c
with selcmd
= unentS v
}
783 | "synctex-command" -> { c
with stcmd
= unentS v
}
784 | "pax-command" -> { c
with paxcmd
= unentS v
}
785 | "askpass-command" -> { c
with passcmd
= unentS v
}
786 | "savepath-command" -> { c
with savecmd
= unentS v
}
787 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
788 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
789 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
790 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
791 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
792 | "horizontal-scrollbar-visible" ->
795 then c
.scrollb
lor scrollbhv
796 else c
.scrollb
land (lnot scrollbhv
)
798 { c
with scrollb
= b }
799 | "vertical-scrollbar-visible" ->
802 then c
.scrollb
lor scrollbvv
803 else c
.scrollb
land (lnot scrollbvv
)
805 { c
with scrollb
= b }
806 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
812 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
813 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
814 | "title" -> { c
with title
= unentS v
}
815 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
816 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
817 | "coarse-presentation-positioning" ->
818 { c
with coarseprespos
= bool_of_string v
}
819 | "use-document-css" -> { c
with usedoccss
= bool_of_string v
}
822 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
825 let rec fold c
= function
828 let c = apply c k v
in
831 fold { c with keyhashes
= copykeyhashes
c } attrs
;
834 let fromstring f pos
n v
d =
837 dolog
"error processing attribute (%S=%S) at %d\n%s" n v pos
@@ exntos exn
;
841 let bookmark_of attrs
=
842 let rec fold title page rely visy
= function
843 | ("title", v
) :: rest
-> fold v page rely visy rest
844 | ("page", v
) :: rest
-> fold title v rely visy rest
845 | ("rely", v
) :: rest
-> fold title page v visy rest
846 | ("visy", v
) :: rest
-> fold title page rely v rest
847 | _ :: rest
-> fold title page rely visy rest
848 | [] -> title
, page
, rely
, visy
850 fold "invalid" "0" "0" "0" attrs
854 let rec fold path key page rely pan visy origin
= function
855 | ("path", v
) :: rest
-> fold v key page rely pan visy origin rest
856 | ("key", v
) :: rest
-> fold path v page rely pan visy origin rest
857 | ("page", v
) :: rest
-> fold path key v rely pan visy origin rest
858 | ("rely", v
) :: rest
-> fold path key page v pan visy origin rest
859 | ("pan", v
) :: rest
-> fold path key page rely v visy origin rest
860 | ("visy", v
) :: rest
-> fold path key page rely pan v origin rest
861 | ("origin", v
) :: rest
-> fold path key page rely pan visy v rest
862 | _ :: rest
-> fold path key page rely pan visy origin rest
863 | [] -> path
, key
, page
, rely
, pan
, visy
, origin
865 fold E.s E.s "0" "0" "0" "0" E.s attrs
869 let rec fold rs ls
= function
870 | ("out", v
) :: rest
-> fold v ls rest
871 | ("in", v
) :: rest
-> fold rs v rest
872 | _ :: rest
-> fold ls rs rest
878 let findkeyhash c name =
879 try List.assoc
name c.keyhashes
880 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
885 let h = Hashtbl.create
10 in
886 let dc = { defconf
with angle
= defconf
.angle
} in
887 let rec toplevel v t spos
_ =
889 | Vdata
| Vcdata
| Vend
-> v
890 | Vopen
("llppconfig", _, closed
) ->
893 else { v
with f = llppconfig
}
894 | Vopen
_ -> parse_error
"unexpected subelement at top level" s spos
895 | Vclose
_ -> parse_error
"unexpected close at top level" s spos
897 and llppconfig v t spos
_ =
899 | Vdata
| Vcdata
-> v
900 | Vend
-> parse_error
"unexpected end of input in llppconfig" s spos
901 | Vopen
("defaults", attrs
, closed
) ->
902 let c = config_of dc attrs
in
906 else { v
with f = defaults
}
908 | Vopen
("ui-font", attrs
, closed
) ->
909 let rec getsize size
= function
911 | ("size", v
) :: rest
->
913 fromstring int_of_string spos
"size" v
fstate.fontsize
in
915 | l -> getsize size l
917 fstate.fontsize
<- getsize fstate.fontsize attrs
;
920 else { v
with f = uifont
(Buffer.create
10) }
922 | Vopen
("doc", attrs
, closed
) ->
923 let pathent, key
, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
924 let path = unentS pathent
925 and origin
= unentS origin
926 and pageno = fromstring int_of_string spos
"page" spage
0
927 and rely
= fromstring float_of_string spos
"rely" srely
0.0
928 and pan
= fromstring int_of_string spos
"pan" span
0
929 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
930 let c = config_of dc attrs
in
932 let anchor = (pageno, rely
, visy
) in
934 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
935 else { v
with f = doc
path origin pan
anchor c [] }
938 parse_error
"unexpected subelement in llppconfig" s spos
940 | Vclose
"llppconfig" -> { v
with f = toplevel }
941 | Vclose
_ -> parse_error
"unexpected close in llppconfig" s spos
943 and defaults v t spos
_ =
945 | Vdata
| Vcdata
-> v
946 | Vend
-> parse_error
"unexpected end of input in defaults" s spos
947 | Vopen
("keymap", attrs
, closed
) ->
949 try List.assoc
"mode" attrs
950 with Not_found
-> "global" in
955 let h = findkeyhash dc modename in
956 KeyMap.iter
(Hashtbl.replace
h) keymap
;
959 { v
with f = pkeymap
ret KeyMap.empty
}
962 parse_error
"unexpected subelement in defaults" s spos
964 | Vclose
"defaults" ->
965 { v
with f = llppconfig
}
967 | Vclose
_ -> parse_error
"unexpected close in defaults" s spos
969 and uifont
b v t spos epos
=
972 Buffer.add_substring
b s spos
(epos
- spos
);
975 parse_error
"unexpected subelement in ui-font" s spos
976 | Vclose
"ui-font" ->
977 if emptystr
!fontpath
978 then fontpath := Buffer.contents
b;
979 { v
with f = llppconfig
}
980 | Vclose
_ -> parse_error
"unexpected close in ui-font" s spos
981 | Vend
-> parse_error
"unexpected end of input in ui-font" s spos
983 and doc
path origin pan
anchor c bookmarks v t spos
_ =
985 | Vdata
| Vcdata
-> v
986 | Vend
-> parse_error
"unexpected end of input in doc" s spos
987 | Vopen
("bookmarks", _, closed
) ->
990 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
992 | Vopen
("keymap", attrs
, closed
) ->
994 try List.assoc
"mode" attrs
995 with Not_found
-> "global"
1001 let h = findkeyhash c modename in
1002 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1003 doc
path origin pan
anchor c bookmarks
1005 { v
with f = pkeymap
ret KeyMap.empty
}
1007 | Vopen
("css", [], false) ->
1008 { v
with f = pcss
path origin pan
anchor c bookmarks
}
1010 | Vopen
(_, _, _) ->
1011 parse_error
"unexpected subelement in doc" s spos
1014 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
1015 { v
with f = llppconfig
}
1017 | Vclose
_ -> parse_error
"unexpected close in doc" s spos
1019 and pcss
path origin pan
anchor c bookmarks v t spos epos
=
1022 let b = Buffer.create
10 in
1023 Buffer.add_substring
b s spos
(epos
- spos
);
1024 { v
with f = pcss
path origin pan
anchor
1025 { c with css
= Buffer.contents
b }
1027 | Vend
-> parse_error
"unexpected end of input in css" s spos
1028 | Vopen
_ -> parse_error
"unexpected subelement in css" s spos
1029 | Vclose
"css" -> { v
with f = doc
path origin pan
anchor c bookmarks
}
1030 | Vclose
_ -> parse_error
"unexpected close in css" s spos
1032 and pkeymap
ret keymap v t spos
_ =
1034 | Vdata
| Vcdata
-> v
1035 | Vend
-> parse_error
"unexpected end of input in keymap" s spos
1036 | Vopen
("map", attrs
, closed
) ->
1037 let r, l = map_of attrs
in
1038 let kss = fromstring keys_of_string spos
"in" r [] in
1039 let lss = fromstring keys_of_string spos
"out" l [] in
1043 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1044 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1047 then { v
with f = pkeymap
ret keymap }
1050 { v
with f = skip
"map" f }
1053 parse_error
"unexpected subelement in keymap" s spos
1055 | Vclose
"keymap" ->
1056 { v
with f = ret keymap }
1058 | Vclose
_ -> parse_error
"unexpected close in keymap" s spos
1060 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1062 | Vdata
| Vcdata
-> v
1063 | Vend
-> parse_error
"unexpected end of input in bookmarks" s spos
1064 | Vopen
("item", attrs
, closed
) ->
1065 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1066 let page = fromstring int_of_string spos
"page" spage
0
1067 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1068 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1070 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1073 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1076 { v
with f = skip
"item" f }
1079 parse_error
"unexpected subelement in bookmarks" s spos
1081 | Vclose
"bookmarks" ->
1082 { v
with f = doc
path origin pan
anchor c bookmarks }
1084 | Vclose
_ -> parse_error
"unexpected close in bookmarks" s spos
1086 and skip tag
f v t spos
_ =
1088 | Vdata
| Vcdata
-> v
1090 parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1091 | Vopen
(tag'
, _, closed
) ->
1095 let f'
() = { v
with f = skip tag
f } in
1096 { v
with f = skip tag'
f'
}
1100 else parse_error
("unexpected close in skipped " ^ tag
) s spos
1103 parse
{ f = toplevel; accu
= () } s;
1107 let do_load f contents
=
1110 | Parser.Parse_error
(msg
, s, pos
) ->
1111 let subs = Parser.subs s pos
in
1112 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1114 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1119 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1120 if emptystr
xdgconfdir
1123 let dir = Filename.concat
home ".config" in
1124 if Sys.is_directory
dir then dir else home
1128 Filename.concat
dir "llpp.conf"
1131 let confpath = ref defconfpath;;
1133 let load2 f default
=
1134 match filecontents
!confpath with
1135 | contents
-> f @@ do_load get contents
1136 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1137 f (Hashtbl.create
0, defconf
)
1139 dolog
"error loading configuration from `%S': %s" !confpath @@ exntos exn
;
1143 let load1 f = load2 f false;;
1151 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1152 if conf.lastvisit
> besttime
1153 then (path, conf.lastvisit
)
1156 (state.path, -.infinity
)
1160 let pc, pb
, px
, pa
, po
=
1161 let def = dc, [], 0, emptyanchor, state.origin
in
1162 if emptystr
state.path
1165 let absname = abspath
state.path in
1166 match Hashtbl.find h absname with
1167 | (c,b,x
,a
,_) -> (c,b,x
,a
,state.origin
)
1168 | exception Not_found
->
1169 let exception E
of (conf * outline list
* int * anchor * string) in
1170 let key = try Digest.file
absname |> Digest.to_hex
with _ -> E.s in
1175 Hashtbl.iter
(fun p
((c, _, _, _, _) as v
) ->
1178 dolog
"will use %s's settings due to matching keys" p
;
1185 | exception E v
-> v
1189 state.bookmarks <- pb
;
1193 cbput state.hists
.nav pa
;
1201 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1202 (path, pc, pb
, px
, pa
, po
) :: accu
)
1208 let add_attrs bb always
dc c time
=
1210 Buffer.add_string bb
"\n ";
1211 Printf.bprintf bb fmt
s
1213 let o c fmt
s = if c then o' fmt
s else ignore
in
1214 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1215 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1216 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1217 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1218 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1219 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1220 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1221 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1222 and oA
s a
b = o (always
|| a
<> b) "%s='%s'" s (rgba_to_string a
)
1223 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1224 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1225 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1227 o (always
|| a
land m
<> b land m
) "%s='%b'" s (a
land m
!= 0)
1228 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1230 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1235 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1236 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1237 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1242 | Some
c when c > 1 -> o'
"%s='%d'" s c
1245 oi
"width" c.cwinw
dc.cwinw
;
1246 oi
"height" c.cwinh
dc.cwinh
;
1247 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1248 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1249 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb scrollbhv
;
1250 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb scrollbvv
;
1251 ob "case-insensitive-search" c.icase
dc.icase
;
1252 ob "preload" c.preload
dc.preload
;
1253 oi
"page-bias" c.pagebias
dc.pagebias
;
1254 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1255 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1256 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1257 ob "highlight-links" c.hlinks
dc.hlinks
;
1258 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1259 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1260 oz
"zoom" c.zoom dc.zoom;
1261 ob "presentation" c.presentation
dc.presentation
;
1262 oi
"rotation-angle" c.angle
dc.angle
;
1263 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1264 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1265 oi
"tex-count" c.texcount
dc.texcount
;
1266 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1267 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1268 oc
"background-color" c.bgcolor
dc.bgcolor
;
1269 oA
"scrollbar-color" c.sbarcolor
dc.sbarcolor
;
1270 oA
"scrollbar-handle-color" c.sbarhndlcolor
dc.sbarhndlcolor
;
1271 oi
"tile-width" c.tilew
dc.tilew
;
1272 oi
"tile-height" c.tileh
dc.tileh
;
1273 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1274 ob "checkers" c.checkers
dc.checkers
;
1275 oi
"aalevel" c.aalevel
dc.aalevel
;
1276 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1277 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1278 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1279 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1280 oC
"color-space" c.colorspace
dc.colorspace
;
1281 ob "invert-colors" c.invert
dc.invert
;
1282 oF
"brightness" c.colorscale
dc.colorscale
;
1283 oco
"columns" c.columns
dc.columns
;
1284 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1285 os
"selection-command" c.selcmd
dc.selcmd
;
1286 os
"synctex-command" c.stcmd
dc.stcmd
;
1287 os
"pax-command" c.paxcmd
dc.paxcmd
;
1288 os
"askpass-command" c.passcmd
dc.passcmd
;
1289 os
"savepath-command" c.savecmd
dc.savecmd
;
1290 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1291 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1292 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1293 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1294 ob "use-pbo" c.usepbo
dc.usepbo
;
1295 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1296 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1297 op
"point-and-x" c.pax
dc.pax
;
1298 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1299 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1301 then os
"title" c.title
dc.title
;
1302 oL
"last-visit" (Int64.of_float time
) 0L;
1303 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1304 ob "coarse-presentation-positioning" c.coarseprespos
dc.coarseprespos
;
1305 ob "use-document-css" c.usedoccss
dc.usedoccss
;
1308 let keymapsbuf always
dc c =
1310 let bb = create
16 in
1311 let rec loop = function
1313 | (modename, h) :: rest
->
1314 let dh = findkeyhash dc modename in
1315 if always
|| h <> dh
1317 if Hashtbl.length
h > 0
1319 if length
bb > 0 then add_char
bb '
\n'
;
1320 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1321 Hashtbl.iter
(fun i
o ->
1322 if always
|| match Hashtbl.find dh i
1323 with | dO
-> dO
<> o | exception Not_found
-> false
1326 if Wsi.withctrl m
then add_string
bb "ctrl-";
1327 if Wsi.withalt m
then add_string
bb "alt-";
1328 if Wsi.withshift m
then add_string
bb "shift-";
1329 if Wsi.withmeta m
then add_string
bb "meta-";
1330 add_string
bb (Wsi.keyname
k);
1333 let rec loop = function
1335 | km
:: [] -> addkm km
1336 | km
:: rest
-> addkm km
; add_char
bb ' '
; loop rest
1340 add_string
bb "<map in='";
1344 add_string
bb "' out='"; addkm km
; add_string
bb "'/>\n"
1347 add_string
bb "' out='"; addkms kms
; add_string
bb "'/>\n"
1349 | KMmulti
(ins
, kms
) ->
1350 add_char
bb ' '
; addkms ins
; add_string
bb "' out='";
1351 addkms kms
; add_string
bb "'/>\n"
1353 add_string
bb "</keymap>";
1362 let keystostrlist c =
1363 let rec loop accu
= function
1365 | (modename, h) :: rest
->
1367 if Hashtbl.length
h > 0
1369 let accu = Printf.sprintf
"\xc2\xb7Keys for %s" modename :: accu in
1370 Hashtbl.fold (fun i
o a
->
1371 let bb = Buffer.create
10 in
1373 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1374 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1375 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1376 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1377 Buffer.add_string
bb (Wsi.keyname
k);
1380 let rec loop = function
1382 | km
:: [] -> addkm km
1384 addkm km
; Buffer.add_char
bb ' '
;
1390 Buffer.add_char
bb '
\t'
;
1398 | KMmulti
(ins
, kms
) ->
1399 Buffer.add_char
bb ' '
;
1401 Buffer.add_string
bb "\t";
1404 Buffer.contents
bb :: a
1414 let save1 bb leavebirdseye x
h dc =
1415 let uifontsize = fstate.fontsize
in
1416 let dc = if conf.bedefault
then conf else dc in
1417 Buffer.add_string
bb "<llppconfig>\n";
1419 if nonemptystr
!fontpath
1421 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1427 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1430 Buffer.add_string
bb "<defaults";
1431 add_attrs bb true dc dc nan
;
1432 let kb = keymapsbuf true dc dc in
1433 if Buffer.length
kb > 0
1435 Buffer.add_string
bb ">\n";
1436 Buffer.add_buffer
bb kb;
1437 Buffer.add_string
bb "\n</defaults>\n";
1439 else Buffer.add_string
bb "/>\n";
1441 let adddoc path pan
anchor c bookmarks time origin
=
1442 if bookmarks == [] && c = dc && anchor = emptyanchor
1445 Printf.bprintf
bb "<doc path='%s'"
1446 (Parser.enent
path 0 (String.length
path));
1448 if nonemptystr
c.key
1450 Printf.bprintf
bb "\n key='%s'" c.key;
1452 if nonemptystr origin
1453 then Printf.bprintf
bb "\n origin='%s'"
1454 (Parser.enent origin
0 (String.length origin
));
1456 if anchor <> emptyanchor
1458 let n, rely
, visy
= anchor in
1459 Printf.bprintf
bb "\n page='%d'" n;
1462 then Printf.bprintf
bb " rely='%f'" rely
;
1464 if abs_float visy
> 1e-6
1465 then Printf.bprintf
bb " visy='%f'" visy
;
1469 then Printf.bprintf
bb " pan='%d'" pan
;
1471 add_attrs bb false dc c time
;
1472 if nonemptystr
c.css
1473 then Printf.bprintf
bb ">\n <css><![CDATA[%s]]></css>" c.css
;
1474 let kb = keymapsbuf false dc c in
1476 begin match bookmarks with
1478 if Buffer.length
kb > 0
1480 Buffer.add_string
bb ">\n";
1481 Buffer.add_buffer
bb kb;
1482 Buffer.add_string
bb "\n</doc>\n";
1485 if nonemptystr
c.css
1486 then Buffer.add_string
bb "\n</doc>\n"
1487 else Buffer.add_string
bb "/>\n"
1489 Buffer.add_string
bb ">\n<bookmarks>\n";
1490 List.iter
(fun (title
, _, kind
) ->
1491 begin match kind
with
1492 | Oanchor
(page, rely
, visy
) ->
1494 "<item title='%s' page='%d'"
1495 (Parser.enent title
0 (String.length title
))
1500 Printf.bprintf
bb " rely='%f'" rely
1502 if abs_float visy
> 1e-6
1504 Printf.bprintf
bb " visy='%f'" visy
1506 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1507 | Oremotedest
_ | Olaunch
_ ->
1508 failwith
"unexpected link in bookmarks"
1510 Buffer.add_string
bb "/>\n";
1512 Buffer.add_string
bb "</bookmarks>";
1513 if Buffer.length
kb > 0
1515 Buffer.add_string
bb "\n";
1516 Buffer.add_buffer
bb kb;
1518 Buffer.add_string
bb "\n</doc>\n";
1524 match state.mode
with
1525 | Birdseye
(c, pan, _, _, _) ->
1527 match conf.columns
with
1528 | Cmulti
((c, _, _), _) -> Some
c
1532 match c.columns
with
1533 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1534 | Csingle
_ -> Csingle
E.a
1535 | Csplit
_ -> failwith
"quit from bird's eye while split"
1537 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1540 | LinkNav
_ -> x
, conf
1542 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1543 if nonemptystr
docpath
1545 adddoc docpath pan (getanchor ())
1547 let autoscrollstep =
1548 match state.autoscroll
with
1550 | None
-> conf.autoscrollstep
1552 begin match state.mode
with
1553 | Birdseye beye
-> leavebirdseye beye
true
1558 let key = try Digest.file
docpath |> Digest.to_hex
1560 { conf with autoscrollstep; key }
1566 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1567 if docpath <> abspath
path
1568 then adddoc path x
anchor c bookmarks c.lastvisit origin
1570 Buffer.add_string
bb "</llppconfig>\n";
1574 let save leavebirdseye
=
1575 let relx = float state.x
/. float state.winw
in
1577 let cx w = truncate
(relx *. float w) in
1579 (fun (w, h, x
) ws
->
1581 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1582 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1583 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1585 (state.winw
, state.winh
, state.x
) state.winstate
1589 let bb = Buffer.create
32768 in
1591 save1 bb leavebirdseye x
h dc
1593 if load1 save2 && Buffer.length
bb > 0
1596 let tmp = !confpath ^
".tmp" in
1597 let oc = open_out_bin
tmp in
1598 Buffer.output_buffer
oc bb;
1600 Unix.rename
tmp !confpath;
1602 dolog
"error saving configuration: %s" @@ exntos exn
1606 let href = ref @@ Hashtbl.create
0 in
1607 let cref = ref defconf
in
1610 if Sys.file_exists
path
1612 else (dolog
"removing entry for '%s'" path; None
) in
1613 Hashtbl.filter_map_inplace
f h;
1618 ignore
(load1 push);
1619 let bb = Buffer.create
32768 in
1620 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1621 if load1 save2 && Buffer.length
bb > 0
1624 let tmp = !confpath ^
".tmp" in
1625 let oc = open_out_bin
tmp in
1626 Buffer.output_buffer
oc bb;
1628 Unix.rename
tmp !confpath;
1630 dolog
"error saving configuration: %s" @@ exntos exn
1634 let logcurrently = function
1635 | Idle
-> dolog
"Idle"
1636 | Loading
(l, gen
) ->
1637 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
1638 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
1639 dolog
"Tiling %d[%d,%d] page=%s cs=%s angle=%d"
1640 l.pageno col row
(~
> pageopaque
)
1641 (CSTE.to_string colorspace
) angle
;
1642 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1643 angle gen
conf.angle
state.gen
1645 conf.tilew
conf.tileh
1646 | Outlining
_ -> dolog
"outlining"