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 | Csingle b
-> (1, 0, 0), b
486 | Cmulti
(c
, b
) -> c
, b
487 | Csplit
(_, b
) -> (1, 0, 0), b
489 if Array.length b
= 0
492 let rec bsearch nmin nmax
=
494 then bound nmin
0 (state.pagecount
-1)
496 let n = (nmax
+ nmin
) / 2 in
497 let vy, h
= rowyh cl b
n in
501 let ips = calcips h
in
503 let y1 = vy + h
+ ips in
507 then 0, vy + h
+ conf.interpagespace
509 let y0 = vy - conf.interpagespace
in
510 y0, y0 + h
+ conf.interpagespace
520 if n < state.pagecount
- coverB
521 then ((n-coverA
)/c
)*c
+ coverA
528 then bsearch (n+1) nmax
529 else bsearch nmin
(n-1)
532 bsearch 0 (state.pagecount
-1);
536 match conf.columns
with
537 | Cmulti
((_, _, _) as cl
, b
) ->
538 if Array.length b
> 0
540 let y, h
= rowyh cl b
(Array.length b
- 1) in
541 y + h
+ (if conf.presentation
then calcips h
else 0)
544 if Array.length b
> 0
546 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
547 y + h
+ (if conf.presentation
then calcips h
else 0)
550 if Array.length b
> 0
552 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
557 let getpageywh pageno
=
558 let pageno = bound
pageno 0 (state.pagecount
-1) in
559 match conf.columns
with
561 if Array.length b
= 0
564 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
572 if Array.length b
= 0
575 let y, h
= rowyh cl b
pageno in
576 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
584 if Array.length b
= 0
588 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
592 let getpageyh pageno =
593 let y,_,h
= getpageywh pageno in
597 let getpagedim pageno =
600 | (n, _, _, _) as pdim
:: rest
->
602 then (if n = pageno then pdim
else ppdim
)
607 f (-1, -1, -1, -1) state.pdims
610 let getpdimno pageno =
614 | (n, _, _, _) :: rest
->
616 then (if n = pageno then np else p
)
624 let getpagey pageno = fst
(getpageyh pageno);;
628 let coloff = l
.pagecol
* l
.pageh
in
629 float (l
.pagey
+ coloff) /. float l
.pageh
637 then float l
.pagedispy
/. float (calcips l
.pageh
)
638 else float l
.pagedispy
/. float conf.interpagespace
641 (l
.pageno, top, dtop)
645 match state.layout
with
646 | l
:: _ -> getanchor1 l
648 let n = page_of_y state.y in
652 let y, h
= getpageyh n in
653 let dy = y - state.y in
657 let ips = calcips h
in
658 float (dy + ips) /. float ips
660 float dy /. float conf.interpagespace
665 let fontpath = ref E.s;;
667 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
670 Map.Make
(struct type t
= (int * int) let compare = compare end);;
673 let l = String.length
s in
674 let b = Buffer.create
l in
675 Parser.unent
b s 0 l;
680 try Sys.getenv
"HOME"
682 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
686 let modifier_of_string = function
687 | "alt" -> Wsi.altmask
688 | "shift" -> Wsi.shiftmask
689 | "ctrl" | "control" -> Wsi.ctrlmask
690 | "meta" -> Wsi.metamask
694 let keys_of_string s =
695 let key_of_string r
s =
696 let elems = Str.full_split r
s in
699 let m1 = modifier_of_string s in
701 then (Wsi.namekey
s, m
)
704 | Str.Delim
s when n land 1 = 0 -> g s
706 | Str.Delim
_ -> (k
, m
)
708 let rec loop n k m
= function
711 let k, m
= f n k m x
in
716 let elems = Str.split whitere
s in
717 List.map
(key_of_string (Str.regexp
"-")) elems
720 let config_of c attrs
=
724 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
725 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
726 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
727 | "preload" -> { c
with preload
= bool_of_string v
}
728 | "page-bias" -> { c
with pagebias
= int_of_string v
}
729 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
730 | "horizontal-scroll-step" ->
731 { c
with hscrollstep
= max
(int_of_string v
) 1 }
732 | "auto-scroll-step" ->
733 { c
with autoscrollstep
= max
0 (int_of_string v
) }
734 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
735 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
736 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
737 | "vertical-margin" ->
738 { c
with interpagespace
= max
0 (int_of_string v
) }
740 let zoom = float_of_string v
/. 100. in
741 let zoom = max
zoom 0.0 in
742 { c
with zoom = zoom }
743 | "presentation" -> { c
with presentation
= bool_of_string v
}
744 | "rotation-angle" -> { c
with angle
= int_of_string v
}
745 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
746 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
747 | "proportional-display" ->
753 { c
with fitmodel
= fm }
754 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
755 | "pixmap-cache-size" ->
756 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
757 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
758 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
759 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
760 | "background-color" -> { c
with bgcolor
= color_of_string v
}
761 | "scrollbar-color" -> { c
with sbarcolor
= rgba_of_string v
}
762 | "scrollbar-handle-color" -> { c
with sbarhndlcolor
= rgba_of_string v
}
763 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
764 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
765 | "mupdf-store-size" ->
766 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
767 | "checkers" -> { c
with checkers
= bool_of_string v
}
768 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
769 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
770 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
771 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
772 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
773 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
774 | "invert-colors" -> { c
with invert
= bool_of_string v
}
775 | "brightness" -> { c
with colorscale
= float_of_string v
}
777 let (n, _, _) as nab
= multicolumns_of_string v
in
779 then { c
with columns
= Csplit
(-n, E.a
) }
780 else { c
with columns
= Cmulti
(nab
, E.a
) }
781 | "birds-eye-columns" ->
782 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
783 | "selection-command" -> { c
with selcmd
= unentS v
}
784 | "synctex-command" -> { c
with stcmd
= unentS v
}
785 | "pax-command" -> { c
with paxcmd
= unentS v
}
786 | "askpass-command" -> { c
with passcmd
= unentS v
}
787 | "savepath-command" -> { c
with savecmd
= unentS v
}
788 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
789 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
790 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
791 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
792 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
793 | "horizontal-scrollbar-visible" ->
796 then c
.scrollb
lor scrollbhv
797 else c
.scrollb
land (lnot scrollbhv
)
799 { c
with scrollb
= b }
800 | "vertical-scrollbar-visible" ->
803 then c
.scrollb
lor scrollbvv
804 else c
.scrollb
land (lnot scrollbvv
)
806 { c
with scrollb
= b }
807 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
813 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
814 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
815 | "title" -> { c
with title
= unentS v
}
816 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
817 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
818 | "coarse-presentation-positioning" ->
819 { c
with coarseprespos
= bool_of_string v
}
820 | "use-document-css" -> { c
with usedoccss
= bool_of_string v
}
823 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
826 let rec fold c
= function
829 let c = apply c k v
in
832 fold { c with keyhashes
= copykeyhashes
c } attrs
;
835 let fromstring f pos
n v
d =
838 dolog
"error processing attribute (%S=%S) at %d\n%s" n v pos
@@ exntos exn
;
842 let bookmark_of attrs
=
843 let rec fold title page rely visy
= function
844 | ("title", v
) :: rest
-> fold v page rely visy rest
845 | ("page", v
) :: rest
-> fold title v rely visy rest
846 | ("rely", v
) :: rest
-> fold title page v visy rest
847 | ("visy", v
) :: rest
-> fold title page rely v rest
848 | _ :: rest
-> fold title page rely visy rest
849 | [] -> title
, page
, rely
, visy
851 fold "invalid" "0" "0" "0" attrs
855 let rec fold path key page rely pan visy origin
= function
856 | ("path", v
) :: rest
-> fold v key page rely pan visy origin rest
857 | ("key", v
) :: rest
-> fold path v page rely pan visy origin rest
858 | ("page", v
) :: rest
-> fold path key v rely pan visy origin rest
859 | ("rely", v
) :: rest
-> fold path key page v pan visy origin rest
860 | ("pan", v
) :: rest
-> fold path key page rely v visy origin rest
861 | ("visy", v
) :: rest
-> fold path key page rely pan v origin rest
862 | ("origin", v
) :: rest
-> fold path key page rely pan visy v rest
863 | _ :: rest
-> fold path key page rely pan visy origin rest
864 | [] -> path
, key
, page
, rely
, pan
, visy
, origin
866 fold E.s E.s "0" "0" "0" "0" E.s attrs
870 let rec fold rs ls
= function
871 | ("out", v
) :: rest
-> fold v ls rest
872 | ("in", v
) :: rest
-> fold rs v rest
873 | _ :: rest
-> fold ls rs rest
879 let findkeyhash c name =
880 try List.assoc
name c.keyhashes
881 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
886 let h = Hashtbl.create
10 in
887 let dc = { defconf
with angle
= defconf
.angle
} in
888 let rec toplevel v t spos
_ =
890 | Vdata
| Vcdata
| Vend
-> v
891 | Vopen
("llppconfig", _, closed
) ->
894 else { v
with f = llppconfig
}
895 | Vopen
_ -> parse_error
"unexpected subelement at top level" s spos
896 | Vclose
_ -> parse_error
"unexpected close at top level" s spos
898 and llppconfig v t spos
_ =
900 | Vdata
| Vcdata
-> v
901 | Vend
-> parse_error
"unexpected end of input in llppconfig" s spos
902 | Vopen
("defaults", attrs
, closed
) ->
903 let c = config_of dc attrs
in
907 else { v
with f = defaults
}
909 | Vopen
("ui-font", attrs
, closed
) ->
910 let rec getsize size
= function
912 | ("size", v
) :: rest
->
914 fromstring int_of_string spos
"size" v
fstate.fontsize
in
916 | l -> getsize size l
918 fstate.fontsize
<- getsize fstate.fontsize attrs
;
921 else { v
with f = uifont
(Buffer.create
10) }
923 | Vopen
("doc", attrs
, closed
) ->
924 let pathent, key
, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
925 let path = unentS pathent
926 and origin
= unentS origin
927 and pageno = fromstring int_of_string spos
"page" spage
0
928 and rely
= fromstring float_of_string spos
"rely" srely
0.0
929 and pan
= fromstring int_of_string spos
"pan" span
0
930 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
931 let c = config_of dc attrs
in
933 let anchor = (pageno, rely
, visy
) in
935 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
936 else { v
with f = doc
path origin pan
anchor c [] }
939 parse_error
"unexpected subelement in llppconfig" s spos
941 | Vclose
"llppconfig" -> { v
with f = toplevel }
942 | Vclose
_ -> parse_error
"unexpected close in llppconfig" s spos
944 and defaults v t spos
_ =
946 | Vdata
| Vcdata
-> v
947 | Vend
-> parse_error
"unexpected end of input in defaults" s spos
948 | Vopen
("keymap", attrs
, closed
) ->
950 try List.assoc
"mode" attrs
951 with Not_found
-> "global" in
956 let h = findkeyhash dc modename in
957 KeyMap.iter
(Hashtbl.replace
h) keymap
;
960 { v
with f = pkeymap
ret KeyMap.empty
}
963 parse_error
"unexpected subelement in defaults" s spos
965 | Vclose
"defaults" ->
966 { v
with f = llppconfig
}
968 | Vclose
_ -> parse_error
"unexpected close in defaults" s spos
970 and uifont
b v t spos epos
=
973 Buffer.add_substring
b s spos
(epos
- spos
);
976 parse_error
"unexpected subelement in ui-font" s spos
977 | Vclose
"ui-font" ->
978 if emptystr
!fontpath
979 then fontpath := Buffer.contents
b;
980 { v
with f = llppconfig
}
981 | Vclose
_ -> parse_error
"unexpected close in ui-font" s spos
982 | Vend
-> parse_error
"unexpected end of input in ui-font" s spos
984 and doc
path origin pan
anchor c bookmarks v t spos
_ =
986 | Vdata
| Vcdata
-> v
987 | Vend
-> parse_error
"unexpected end of input in doc" s spos
988 | Vopen
("bookmarks", _, closed
) ->
991 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
993 | Vopen
("keymap", attrs
, closed
) ->
995 try List.assoc
"mode" attrs
996 with Not_found
-> "global"
1002 let h = findkeyhash c modename in
1003 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1004 doc
path origin pan
anchor c bookmarks
1006 { v
with f = pkeymap
ret KeyMap.empty
}
1008 | Vopen
("css", [], false) ->
1009 { v
with f = pcss
path origin pan
anchor c bookmarks
}
1011 | Vopen
(_, _, _) ->
1012 parse_error
"unexpected subelement in doc" s spos
1015 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
1016 { v
with f = llppconfig
}
1018 | Vclose
_ -> parse_error
"unexpected close in doc" s spos
1020 and pcss
path origin pan
anchor c bookmarks v t spos epos
=
1023 let b = Buffer.create
10 in
1024 Buffer.add_substring
b s spos
(epos
- spos
);
1025 { v
with f = pcss
path origin pan
anchor
1026 { c with css
= Buffer.contents
b }
1028 | Vend
-> parse_error
"unexpected end of input in css" s spos
1029 | Vopen
_ -> parse_error
"unexpected subelement in css" s spos
1030 | Vclose
"css" -> { v
with f = doc
path origin pan
anchor c bookmarks
}
1031 | Vclose
_ -> parse_error
"unexpected close in css" s spos
1033 and pkeymap
ret keymap v t spos
_ =
1035 | Vdata
| Vcdata
-> v
1036 | Vend
-> parse_error
"unexpected end of input in keymap" s spos
1037 | Vopen
("map", attrs
, closed
) ->
1038 let r, l = map_of attrs
in
1039 let kss = fromstring keys_of_string spos
"in" r [] in
1040 let lss = fromstring keys_of_string spos
"out" l [] in
1044 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1045 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1048 then { v
with f = pkeymap
ret keymap }
1051 { v
with f = skip
"map" f }
1054 parse_error
"unexpected subelement in keymap" s spos
1056 | Vclose
"keymap" ->
1057 { v
with f = ret keymap }
1059 | Vclose
_ -> parse_error
"unexpected close in keymap" s spos
1061 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1063 | Vdata
| Vcdata
-> v
1064 | Vend
-> parse_error
"unexpected end of input in bookmarks" s spos
1065 | Vopen
("item", attrs
, closed
) ->
1066 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1067 let page = fromstring int_of_string spos
"page" spage
0
1068 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1069 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1071 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1074 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1077 { v
with f = skip
"item" f }
1080 parse_error
"unexpected subelement in bookmarks" s spos
1082 | Vclose
"bookmarks" ->
1083 { v
with f = doc
path origin pan
anchor c bookmarks }
1085 | Vclose
_ -> parse_error
"unexpected close in bookmarks" s spos
1087 and skip tag
f v t spos
_ =
1089 | Vdata
| Vcdata
-> v
1091 parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1092 | Vopen
(tag'
, _, closed
) ->
1096 let f'
() = { v
with f = skip tag
f } in
1097 { v
with f = skip tag'
f'
}
1101 else parse_error
("unexpected close in skipped " ^ tag
) s spos
1104 parse
{ f = toplevel; accu
= () } s;
1108 let do_load f contents
=
1111 | Parser.Parse_error
(msg
, s, pos
) ->
1112 let subs = Parser.subs s pos
in
1113 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1115 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1120 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1121 if emptystr
xdgconfdir
1124 let dir = Filename.concat
home ".config" in
1125 if Sys.is_directory
dir then dir else home
1129 Filename.concat
dir "llpp.conf"
1132 let confpath = ref defconfpath;;
1134 let load2 f default
=
1135 match filecontents
!confpath with
1136 | contents
-> f @@ do_load get contents
1137 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1138 f (Hashtbl.create
0, defconf
)
1140 dolog
"error loading configuration from `%S': %s" !confpath @@ exntos exn
;
1144 let load1 f = load2 f false;;
1152 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1153 if conf.lastvisit
> besttime
1154 then (path, conf.lastvisit
)
1157 (state.path, -.infinity
)
1161 let pc, pb
, px
, pa
, po
=
1162 let def = dc, [], 0, emptyanchor, state.origin
in
1163 if emptystr
state.path
1166 let absname = abspath
state.path in
1167 match Hashtbl.find h absname with
1168 | (c,b,x
,a
,_) -> (c,b,x
,a
,state.origin
)
1169 | exception Not_found
->
1170 let exception E
of (conf * outline list
* int * anchor * string) in
1171 let key = try Digest.file
absname |> Digest.to_hex
with _ -> E.s in
1176 Hashtbl.iter
(fun p
((c, _, _, _, _) as v
) ->
1179 dolog
"will use %s's settings due to matching keys" p
;
1186 | exception E v
-> v
1190 state.bookmarks <- pb
;
1194 cbput state.hists
.nav pa
;
1202 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1203 (path, pc, pb
, px
, pa
, po
) :: accu
)
1209 let add_attrs bb always
dc c time
=
1211 Buffer.add_string bb
"\n ";
1212 Printf.bprintf bb fmt
s
1214 let o c fmt
s = if c then o' fmt
s else ignore
in
1215 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1216 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1217 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1218 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1219 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1220 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1221 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1222 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1223 and oA
s a
b = o (always
|| a
<> b) "%s='%s'" s (rgba_to_string a
)
1224 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1225 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1226 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1228 o (always
|| a
land m
<> b land m
) "%s='%b'" s (a
land m
!= 0)
1229 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1231 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1236 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1237 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1238 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1243 | Some
c when c > 1 -> o'
"%s='%d'" s c
1246 oi
"width" c.cwinw
dc.cwinw
;
1247 oi
"height" c.cwinh
dc.cwinh
;
1248 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1249 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1250 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb scrollbhv
;
1251 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb scrollbvv
;
1252 ob "case-insensitive-search" c.icase
dc.icase
;
1253 ob "preload" c.preload
dc.preload
;
1254 oi
"page-bias" c.pagebias
dc.pagebias
;
1255 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1256 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1257 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1258 ob "highlight-links" c.hlinks
dc.hlinks
;
1259 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1260 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1261 oz
"zoom" c.zoom dc.zoom;
1262 ob "presentation" c.presentation
dc.presentation
;
1263 oi
"rotation-angle" c.angle
dc.angle
;
1264 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1265 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1266 oi
"tex-count" c.texcount
dc.texcount
;
1267 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1268 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1269 oc
"background-color" c.bgcolor
dc.bgcolor
;
1270 oA
"scrollbar-color" c.sbarcolor
dc.sbarcolor
;
1271 oA
"scrollbar-handle-color" c.sbarhndlcolor
dc.sbarhndlcolor
;
1272 oi
"tile-width" c.tilew
dc.tilew
;
1273 oi
"tile-height" c.tileh
dc.tileh
;
1274 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1275 ob "checkers" c.checkers
dc.checkers
;
1276 oi
"aalevel" c.aalevel
dc.aalevel
;
1277 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1278 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1279 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1280 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1281 oC
"color-space" c.colorspace
dc.colorspace
;
1282 ob "invert-colors" c.invert
dc.invert
;
1283 oF
"brightness" c.colorscale
dc.colorscale
;
1284 oco
"columns" c.columns
dc.columns
;
1285 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1286 os
"selection-command" c.selcmd
dc.selcmd
;
1287 os
"synctex-command" c.stcmd
dc.stcmd
;
1288 os
"pax-command" c.paxcmd
dc.paxcmd
;
1289 os
"askpass-command" c.passcmd
dc.passcmd
;
1290 os
"savepath-command" c.savecmd
dc.savecmd
;
1291 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1292 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1293 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1294 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1295 ob "use-pbo" c.usepbo
dc.usepbo
;
1296 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1297 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1298 op
"point-and-x" c.pax
dc.pax
;
1299 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1300 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1302 then os
"title" c.title
dc.title
;
1303 oL
"last-visit" (Int64.of_float time
) 0L;
1304 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1305 ob "coarse-presentation-positioning" c.coarseprespos
dc.coarseprespos
;
1306 ob "use-document-css" c.usedoccss
dc.usedoccss
;
1309 let keymapsbuf always
dc c =
1311 let bb = create
16 in
1312 let rec loop = function
1314 | (modename, h) :: rest
->
1315 let dh = findkeyhash dc modename in
1316 if always
|| h <> dh
1318 if Hashtbl.length
h > 0
1320 if length
bb > 0 then add_char
bb '
\n'
;
1321 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1322 Hashtbl.iter
(fun i
o ->
1323 if always
|| match Hashtbl.find dh i
1324 with | dO
-> dO
<> o | exception Not_found
-> false
1327 if Wsi.withctrl m
then add_string
bb "ctrl-";
1328 if Wsi.withalt m
then add_string
bb "alt-";
1329 if Wsi.withshift m
then add_string
bb "shift-";
1330 if Wsi.withmeta m
then add_string
bb "meta-";
1331 add_string
bb (Wsi.keyname
k);
1334 let rec loop = function
1336 | km
:: [] -> addkm km
1337 | km
:: rest
-> addkm km
; add_char
bb ' '
; loop rest
1341 add_string
bb "<map in='";
1345 add_string
bb "' out='"; addkm km
; add_string
bb "'/>\n"
1348 add_string
bb "' out='"; addkms kms
; add_string
bb "'/>\n"
1350 | KMmulti
(ins
, kms
) ->
1351 add_char
bb ' '
; addkms ins
; add_string
bb "' out='";
1352 addkms kms
; add_string
bb "'/>\n"
1354 add_string
bb "</keymap>";
1363 let keystostrlist c =
1364 let rec loop accu
= function
1366 | (modename, h) :: rest
->
1368 if Hashtbl.length
h > 0
1370 let accu = Printf.sprintf
"\xc2\xb7Keys for %s" modename :: accu in
1371 Hashtbl.fold (fun i
o a
->
1372 let bb = Buffer.create
10 in
1374 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1375 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1376 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1377 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1378 Buffer.add_string
bb (Wsi.keyname
k);
1381 let rec loop = function
1383 | km
:: [] -> addkm km
1385 addkm km
; Buffer.add_char
bb ' '
;
1391 Buffer.add_char
bb '
\t'
;
1399 | KMmulti
(ins
, kms
) ->
1400 Buffer.add_char
bb ' '
;
1402 Buffer.add_string
bb "\t";
1405 Buffer.contents
bb :: a
1415 let save1 bb leavebirdseye x
h dc =
1416 let uifontsize = fstate.fontsize
in
1417 let dc = if conf.bedefault
then conf else dc in
1418 Buffer.add_string
bb "<llppconfig>\n";
1420 if nonemptystr
!fontpath
1422 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1428 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1431 Buffer.add_string
bb "<defaults";
1432 add_attrs bb true dc dc nan
;
1433 let kb = keymapsbuf true dc dc in
1434 if Buffer.length
kb > 0
1436 Buffer.add_string
bb ">\n";
1437 Buffer.add_buffer
bb kb;
1438 Buffer.add_string
bb "\n</defaults>\n";
1440 else Buffer.add_string
bb "/>\n";
1442 let adddoc path pan
anchor c bookmarks time origin
=
1443 if bookmarks == [] && c = dc && anchor = emptyanchor
1446 Printf.bprintf
bb "<doc path='%s'"
1447 (Parser.enent
path 0 (String.length
path));
1449 if nonemptystr
c.key
1451 Printf.bprintf
bb "\n key='%s'" c.key;
1453 if nonemptystr origin
1454 then Printf.bprintf
bb "\n origin='%s'"
1455 (Parser.enent origin
0 (String.length origin
));
1457 if anchor <> emptyanchor
1459 let n, rely
, visy
= anchor in
1460 Printf.bprintf
bb "\n page='%d'" n;
1463 then Printf.bprintf
bb " rely='%f'" rely
;
1465 if abs_float visy
> 1e-6
1466 then Printf.bprintf
bb " visy='%f'" visy
;
1470 then Printf.bprintf
bb " pan='%d'" pan
;
1472 add_attrs bb false dc c time
;
1473 if nonemptystr
c.css
1474 then Printf.bprintf
bb ">\n <css><![CDATA[%s]]></css>" c.css
;
1475 let kb = keymapsbuf false dc c in
1477 begin match bookmarks with
1479 if Buffer.length
kb > 0
1481 Buffer.add_string
bb ">\n";
1482 Buffer.add_buffer
bb kb;
1483 Buffer.add_string
bb "\n</doc>\n";
1486 if nonemptystr
c.css
1487 then Buffer.add_string
bb "\n</doc>\n"
1488 else Buffer.add_string
bb "/>\n"
1490 Buffer.add_string
bb ">\n<bookmarks>\n";
1491 List.iter
(fun (title
, _, kind
) ->
1492 begin match kind
with
1493 | Oanchor
(page, rely
, visy
) ->
1495 "<item title='%s' page='%d'"
1496 (Parser.enent title
0 (String.length title
))
1501 Printf.bprintf
bb " rely='%f'" rely
1503 if abs_float visy
> 1e-6
1505 Printf.bprintf
bb " visy='%f'" visy
1507 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1508 | Oremotedest
_ | Olaunch
_ ->
1509 failwith
"unexpected link in bookmarks"
1511 Buffer.add_string
bb "/>\n";
1513 Buffer.add_string
bb "</bookmarks>";
1514 if Buffer.length
kb > 0
1516 Buffer.add_string
bb "\n";
1517 Buffer.add_buffer
bb kb;
1519 Buffer.add_string
bb "\n</doc>\n";
1525 match state.mode
with
1526 | Birdseye
(c, pan, _, _, _) ->
1528 match conf.columns
with
1529 | Cmulti
((c, _, _), _) -> Some
c
1533 match c.columns
with
1534 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1535 | Csingle
_ -> Csingle
E.a
1536 | Csplit
_ -> failwith
"quit from bird's eye while split"
1538 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1541 | LinkNav
_ -> x
, conf
1543 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1544 if nonemptystr
docpath
1546 adddoc docpath pan (getanchor ())
1548 let autoscrollstep =
1549 match state.autoscroll
with
1551 | None
-> conf.autoscrollstep
1553 begin match state.mode
with
1554 | Birdseye beye
-> leavebirdseye beye
true
1559 let key = try Digest.file
docpath |> Digest.to_hex
1561 { conf with autoscrollstep; key }
1567 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1568 if docpath <> abspath
path
1569 then adddoc path x
anchor c bookmarks c.lastvisit origin
1571 Buffer.add_string
bb "</llppconfig>\n";
1575 let save leavebirdseye
=
1576 let relx = float state.x
/. float state.winw
in
1578 let cx w = truncate
(relx *. float w) in
1580 (fun (w, h, x
) ws
->
1582 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1583 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1584 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1586 (state.winw
, state.winh
, state.x
) state.winstate
1590 let bb = Buffer.create
32768 in
1592 save1 bb leavebirdseye x
h dc
1594 if load1 save2 && Buffer.length
bb > 0
1597 let tmp = !confpath ^
".tmp" in
1598 let oc = open_out_bin
tmp in
1599 Buffer.output_buffer
oc bb;
1601 Unix.rename
tmp !confpath;
1603 dolog
"error saving configuration: %s" @@ exntos exn
1607 let href = ref @@ Hashtbl.create
0 in
1608 let cref = ref defconf
in
1611 if Sys.file_exists
path
1613 else (dolog
"removing entry for '%s'" path; None
) in
1614 Hashtbl.filter_map_inplace
f h;
1619 ignore
(load1 push);
1620 let bb = Buffer.create
32768 in
1621 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1622 if load1 save2 && Buffer.length
bb > 0
1625 let tmp = !confpath ^
".tmp" in
1626 let oc = open_out_bin
tmp in
1627 Buffer.output_buffer
oc bb;
1629 Unix.rename
tmp !confpath;
1631 dolog
"error saving configuration: %s" @@ exntos exn
1635 let logcurrently = function
1636 | Idle
-> dolog
"Idle"
1637 | Loading
(l, gen
) ->
1638 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
1639 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
1641 "Tiling %d[%d,%d] page=%s cs=%s angle=%d"
1642 l.pageno col row
(~
> pageopaque
)
1643 (CSTE.to_string colorspace
) angle
;
1644 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1645 angle gen
conf.angle
state.gen
1647 conf.tilew
conf.tileh
;