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
) = Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
;;
23 let multicolumns_to_string (n
, a
, b
) =
25 then Printf.sprintf
"%d" n
26 else Printf.sprintf
"%d,%d,%d" n a b
;
29 let multicolumns_of_string s
=
31 (int_of_string s
, 0, 0)
33 Scanf.sscanf s
"%u,%u,%u" (fun n a b
->
35 then error
"subtly broken";
50 and trimcachepath
= string
52 and trimmargins
= bool
53 and trimparams
= (trimmargins
* irect
)
54 and usefontconfig
= bool
60 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
65 | Uannotation
of (opaque
* slinkindex
)
68 and launchcommand
= string
78 | LDfirstvisible
of (int * int * int)
87 and anchor
= pageno
* top
* dtop
88 and rect
= float * float * float * float * float * float * float * float
89 and infochange
= | Memused
| Docinfo
| Pdim
95 method key
: int -> int -> uioh
96 method button
: int -> bool -> int -> int -> int -> uioh
97 method multiclick
: int -> int -> int -> int -> uioh
98 method motion
: int -> int -> uioh
99 method pmotion
: int -> int -> uioh
100 method infochanged
: infochange
-> unit
101 method scrollpw
: (int * float * float)
102 method scrollph
: (int * float * float)
103 method modehash
: keyhash
104 method eformsgs
: bool
105 method alwaysscrolly
: bool
106 method scroll
: int -> int -> uioh
107 method zoom
: float -> int -> int -> unit
110 module type TextEnumType
=
114 val names
: string array
117 module TextEnumMake
(Ten
: TextEnumType
) =
119 let names = Ten.names;;
120 let to_int (t
: Ten.t
) = Obj.magic t
;;
121 let to_string t
= names.(to_int t
);;
122 let of_int n
: Ten.t
= Obj.magic n
;;
125 if i
= Array.length
names
126 then error
"invalid %s: %s" Ten.name s
135 module CSTE
= TextEnumMake
(
137 type t
= colorspace
;;
138 let name = "colorspace";;
139 let names = [|"rgb"; "gray"|];;
142 module MTE
= TextEnumMake
(
146 let names = [|"page"; "block"; "line"; "word"|];;
149 module FMTE
= TextEnumMake
(
152 let name = "fitmodel";;
153 let names = [|"width"; "proportional"; "page"|];;
160 | Olaunch
of launchcommand
161 | Oremote
of (filename
* pageno
)
162 | Oremotedest
of (filename
* destname
)
163 | Ohistory
of (filename
* conf
* outline list
* x
* anchor
* filename
)
164 and outline
= (caption
* outlinelevel
* outlinekind
)
165 and outlinelevel
= int
183 type tile
= opaque
* pixmapsize
* elapsed
184 and elapsed
= float;;
185 type pagemapkey
= pageno
* gen
;;
186 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
191 | Loading
of (page
* gen
)
193 of (page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
)
194 | Outlining
of outline list
197 type mpos
= int * int
199 | Msel
of (mpos
* mpos
)
201 | Mscrolly
| Mscrollx
202 | Mzoom
of (buttonno
* step
* mpos
)
203 | Mzoomrect
of (mpos
* mpos
)
210 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
211 | Textentry
of (textentry
* onleave
)
213 | LinkNav
of linktarget
214 and onleave
= leavetextentrystatus
-> unit
215 and leavetextentrystatus
= | Cancel
| Confirm
216 and helpitem
= string * int * action
219 | Action
of (uioh
-> uioh
)
221 | Ltexact
of (pageno
* direction
)
222 | Ltgendir
of direction
223 | Ltnotready
of (pageno
* direction
)
224 and direction
= int (* -1, 0, 1 *)
225 and textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
226 and onkey
= string -> Keys.t
-> te
227 and ondone
= string -> unit
228 and histcancel
= unit -> unit
229 and onhist
= ((histcmd
-> string) * histcancel
)
230 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
231 and cancelonempty
= bool
236 | TEswitch
of textentry
248 { mutable ss
: Unix.file_descr
249 ; mutable wsfd
: Unix.file_descr
250 ; mutable stderr
: Unix.file_descr
251 ; mutable errmsgs
: Buffer.t
252 ; mutable newerrmsgs
: bool
256 ; mutable anchor
: anchor
257 ; mutable ranchors
: (string * string * anchor
* string) list
259 ; mutable layout
: page list
260 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
261 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
262 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
263 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
264 ; mutable pagecount
: int
265 ; mutable currently
: currently
266 ; mutable mstate
: mstate
267 ; mutable searchpattern
: string
268 ; mutable rects
: (pageno
* rectcolor
* rect
) list
269 ; mutable rects1
: (pageno
* rectcolor
* rect
) list
270 ; prects
: (pageno
, float array
) Hashtbl.t
271 ; mutable text
: string
272 ; mutable winstate
: Wsi.winstate list
273 ; mutable mode
: mode
274 ; mutable uioh
: uioh
275 ; mutable outlines
: outline array
276 ; mutable bookmarks
: outline list
277 ; mutable path
: string
278 ; mutable password
: string
279 ; mutable nameddest
: string
280 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
281 ; mutable memused
: memsize
283 ; mutable autoscroll
: int option
284 ; mutable help
: helpitem array
285 ; mutable docinfo
: (int * string) list
287 ; mutable prevzoom
: (float * int)
288 ; mutable progress
: float
289 ; mutable mpos
: mpos
290 ; mutable keystate
: keystate
291 ; mutable glinks
: bool
292 ; mutable prevcolumns
: (columns
* float) option
295 ; mutable reprf
: (unit -> unit)
296 ; mutable origin
: string
297 ; mutable roam
: (unit -> unit)
298 ; mutable bzoom
: bool
299 ; mutable lnava
: (pageno
* linkno
) option
300 ; mutable slideshow
: int
301 ; mutable reload
: (x
* y
* float) option
304 { pat
: string circbuf
305 ; pag
: string circbuf
306 ; nav
: anchor circbuf
307 ; sel
: string circbuf
311 let emptyanchor = (0, 0.0, 0.0);;
312 let emptykeyhash = Hashtbl.create
0;;
313 let noreprf () = ();;
319 method key _ _
= self
320 method multiclick _ _ _ _
= self
321 method button _ _ _ _ _
= self
322 method motion _ _
= self
323 method pmotion _ _
= self
324 method infochanged _
= ()
325 method scrollpw
= (0, nan
, nan
)
326 method scrollph
= (0, nan
, nan
)
327 method modehash
= emptykeyhash
328 method eformsgs
= false
329 method alwaysscrolly
= false
330 method scroll _ _
= self
331 method zoom _ _ _
= ()
334 let platform_to_string = function
335 | Punknown
-> "unknown"
341 let conf = { defconf
with keyhashes
= copykeyhashes defconf
};;
344 { store
= Array.make n v
351 let cbcap b
= Array.length b
.store
;;
353 let cbput ?
(update_rc
=true) b v
=
356 b
.wc
<- (b
.wc
+ 1) mod cap;
359 b
.len
<- min
(b
.len
+ 1) cap;
362 let cbput_dont_update_rc b v
= cbput ~update_rc
:false b v
;;
364 let cbempty b
= b
.len
= 0;;
366 let cbgetg b circular dir
=
370 let rc = b
.rc + dir
in
382 else bound
rc 0 (b
.len
-1)
388 let cbget b
= cbgetg b
false;;
389 let cbgetc b
= cbgetg b
true;;
394 ; stderr
= Unix.stderr
395 ; errmsgs
= Buffer.create
0
400 ; anchor
= emptyanchor
404 ; tilelru
= Queue.create
()
405 ; pagemap
= Hashtbl.create
10
406 ; tilemap
= Hashtbl.create
10
413 ; prects
= Hashtbl.create
1
417 ; searchpattern
= E.s
425 { nav
= cbnew 10 emptyanchor
435 ; prevzoom
= (1.0, 0)
455 let d = state.winh
- h
in
456 max
conf.interpagespace
((d + 1) / 2)
459 let rowyh (c
, coverA
, coverB
) b n
=
460 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
462 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
465 let n'
= n - coverA
in
468 let e = min
state.pagecount
(s + c
) in
469 let rec find m miny maxh
= if m
= e then miny
, maxh
else
470 let _, _, y
, (_, _, h
, _) = b
.(m
) in
471 let miny = min
miny y
in
472 let maxh = max
maxh h
in
478 let ((c
, coverA
, coverB
) as cl
), b
=
479 match conf.columns
with
480 | Csplit
(_, b
) | Csingle b
-> (1, 0, 0), b
481 | Cmulti
(c
, b
) -> c
, b
483 if Array.length b
= 0
486 let rec bsearch nmin nmax
=
488 then bound nmin
0 (state.pagecount
-1)
490 let n = (nmax
+ nmin
) / 2 in
491 let vy, h
= rowyh cl b
n in
495 let ips = calcips h
in
497 let y1 = vy + h
+ ips in
501 then 0, vy + h
+ conf.interpagespace
503 let y0 = vy - conf.interpagespace
in
504 y0, y0 + h
+ conf.interpagespace
514 if n < state.pagecount
- coverB
515 then ((n-coverA
)/c
)*c
+ coverA
522 then bsearch (n+1) nmax
523 else bsearch nmin
(n-1)
526 bsearch 0 (state.pagecount
-1);
530 match conf.columns
with
531 | Cmulti
((_, _, _) as cl
, b
) ->
532 if Array.length b
> 0
534 let y, h
= rowyh cl b
(Array.length b
- 1) in
535 y + h
+ (if conf.presentation
then calcips h
else 0)
538 if Array.length b
> 0
540 let (_, _, y, (_, _, h
, _)) = 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
551 let getpageywh pageno
=
552 let pageno = bound
pageno 0 (state.pagecount
-1) in
553 match conf.columns
with
555 if Array.length b
= 0
558 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
566 if Array.length b
= 0
569 let y, h
= rowyh cl b
pageno in
570 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
578 if Array.length b
= 0
582 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
586 let getpageyh pageno =
587 let y,_,h
= getpageywh pageno in
591 let getpagedim pageno =
594 | (n, _, _, _) as pdim
:: rest
->
596 then (if n = pageno then pdim
else ppdim
)
600 f (-1, -1, -1, -1) state.pdims
603 let getpdimno pageno =
607 | (n, _, _, _) :: rest
->
609 then (if n = pageno then np else p
)
616 let getpagey pageno = fst
(getpageyh pageno);;
620 let coloff = l
.pagecol
* l
.pageh
in
621 float (l
.pagey
+ coloff) /. float l
.pageh
628 then float l
.pagedispy
/. float (calcips l
.pageh
)
629 else float l
.pagedispy
/. float conf.interpagespace
632 (l
.pageno, top, dtop)
636 match state.layout
with
637 | l
:: _ -> getanchor1 l
639 let n = page_of_y state.y in
643 let y, h
= getpageyh n in
644 let dy = y - state.y in
648 let ips = calcips h
in
649 float (dy + ips) /. float ips
650 else float dy /. float conf.interpagespace
655 let fontpath = ref E.s;;
657 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
660 Map.Make
(struct type t
= (int * int) let compare = compare end);;
663 let l = String.length
s in
664 let b = Buffer.create
l in
665 Parser.unent
b s 0 l;
670 try Sys.getenv
"HOME"
672 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
676 let modifier_of_string = function
677 | "alt" -> Wsi.altmask
678 | "shift" -> Wsi.shiftmask
679 | "ctrl" | "control" -> Wsi.ctrlmask
680 | "meta" -> Wsi.metamask
684 let keys_of_string s =
685 let key_of_string r
s =
686 let elems = Str.full_split r
s in
689 let m1 = modifier_of_string s in
691 then (Wsi.namekey
s, m
)
694 | Str.Delim
s when n land 1 = 0 -> g s
696 | Str.Delim
_ -> (k
, m
)
698 let rec loop n k m
= function
701 let k, m
= f n k m x
in
706 let elems = Str.split
Utils.Re.whitespace
s in
707 List.map
(key_of_string (Str.regexp
"-")) elems
710 let config_of c attrs
=
711 let maxv ?
(f=int_of_string
) u
s = max u
@@ f s in
715 | "scroll-bar-width" -> { c
with scrollbw
= maxv 0 v
}
716 | "scroll-handle-height" -> { c
with scrollh
= maxv 0 v
}
717 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
718 | "preload" -> { c
with preload
= bool_of_string v
}
719 | "page-bias" -> { c
with pagebias
= int_of_string v
}
720 | "scroll-step" -> { c
with scrollstep
= maxv 1 v
}
721 | "horizontal-scroll-step" -> { c
with hscrollstep
= maxv 1 v
}
722 | "auto-scroll-step" -> { c
with autoscrollstep
= maxv 0 v
}
723 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
724 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
725 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
726 | "vertical-margin" -> { c
with interpagespace
= maxv 0 v
}
728 let zoom = float_of_string v
/. 100. in
729 let zoom = max
zoom 0.0 in
730 { c
with zoom = zoom }
731 | "presentation" -> { c
with presentation
= bool_of_string v
}
732 | "rotation-angle" -> { c
with angle
= int_of_string v
}
733 | "width" -> { c
with cwinw
= maxv 20 v
}
734 | "height" -> { c
with cwinh
= maxv 20 v
}
735 | "proportional-display" ->
741 { c
with fitmodel
= fm }
742 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
743 | "pixmap-cache-size" ->
744 { c
with memlimit
= maxv ~
f:int_of_string_with_suffix
2 v
}
745 | "tex-count" -> { c
with texcount
= maxv 1 v
}
746 | "slice-height" -> { c
with sliceheight
= maxv 2 v
}
747 | "thumbnail-width" -> { c
with thumbw
= maxv 2 v
}
748 | "background-color" -> { c
with bgcolor
= color_of_string v
}
749 | "scrollbar-color" -> { c
with sbarcolor
= rgba_of_string v
}
750 | "scrollbar-handle-color" -> { c
with sbarhndlcolor
= rgba_of_string v
}
751 | "texture-color" -> { c
with texturecolor
= rgba_of_string v
}
752 | "tile-width" -> { c
with tilew
= maxv 2 v
}
753 | "tile-height" -> { c
with tileh
= maxv 2 v
}
754 | "mupdf-store-size" ->
755 { c
with mustoresize
= maxv ~
f:int_of_string_with_suffix
1024 v
}
756 | "checkers" -> { c
with checkers
= bool_of_string v
}
757 | "aalevel" -> { c
with aalevel
= maxv 0 v
}
758 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
759 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
760 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
761 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
762 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
763 | "invert-colors" -> { c
with invert
= bool_of_string v
}
764 | "brightness" -> { c
with colorscale
= float_of_string v
}
766 let (n, _, _) as nab
= multicolumns_of_string v
in
768 then { c
with columns
= Csplit
(-n, E.a
) }
769 else { c
with columns
= Cmulti
(nab
, E.a
) }
770 | "birds-eye-columns" -> { c
with beyecolumns
= Some
(maxv 2 v
) }
771 | "selection-command" -> { c
with selcmd
= unentS v
}
772 | "paste-command" -> { c
with pastecmd
= unentS v
}
773 | "synctex-command" -> { c
with stcmd
= unentS v
}
774 | "pax-command" -> { c
with paxcmd
= unentS v
}
775 | "askpass-command" -> { c
with passcmd
= unentS v
}
776 | "savepath-command" -> { c
with savecmd
= unentS v
}
777 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
778 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
779 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
780 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
781 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
782 | "horizontal-scrollbar-visible" ->
783 { c
with scrollb
= if bool_of_string v
784 then c
.scrollb
lor scrollbhv
785 else c
.scrollb
land (lnot scrollbhv
)
787 | "vertical-scrollbar-visible" ->
788 { c
with scrollb
= if bool_of_string v
789 then c
.scrollb
lor scrollbvv
790 else c
.scrollb
land (lnot scrollbvv
)
792 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
794 { c
with pax
= if bool_of_string v
then Some
0.0 else None
}
795 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
796 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
797 | "title" -> { c
with title
= unentS v
}
798 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
799 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
800 | "coarse-presentation-positioning" ->
801 { c
with coarseprespos
= bool_of_string v
}
802 | "use-document-css" -> { c
with usedoccss
= bool_of_string v
}
805 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
808 let rec fold c
= function
811 let c = apply c k v
in
814 fold { c with keyhashes
= copykeyhashes
c } attrs
;
817 let fromstring f pos
n v
d =
820 dolog
"error processing attribute (%S=%S) at %d\n%s" n v pos
@@ exntos exn
;
824 let bookmark_of attrs
=
825 let rec fold title page rely visy
= function
826 | ("title", v
) :: rest
-> fold v page rely visy rest
827 | ("page", v
) :: rest
-> fold title v rely visy rest
828 | ("rely", v
) :: rest
-> fold title page v visy rest
829 | ("visy", v
) :: rest
-> fold title page rely v rest
830 | _ :: rest
-> fold title page rely visy rest
831 | [] -> title
, page
, rely
, visy
833 fold "invalid" "0" "0" "0" attrs
837 let rec fold path key page rely pan visy origin
= function
838 | ("path", v
) :: rest
-> fold v key page rely pan visy origin rest
839 | ("key", v
) :: rest
-> fold path v page rely pan visy origin rest
840 | ("page", v
) :: rest
-> fold path key v rely pan visy origin rest
841 | ("rely", v
) :: rest
-> fold path key page v pan visy origin rest
842 | ("pan", v
) :: rest
-> fold path key page rely v visy origin rest
843 | ("visy", v
) :: rest
-> fold path key page rely pan v origin rest
844 | ("origin", v
) :: rest
-> fold path key page rely pan visy v rest
845 | _ :: rest
-> fold path key page rely pan visy origin rest
846 | [] -> path
, key
, page
, rely
, pan
, visy
, origin
848 fold E.s E.s "0" "0" "0" "0" E.s attrs
852 let rec fold rs ls
= function
853 | ("out", v
) :: rest
-> fold v ls rest
854 | ("in", v
) :: rest
-> fold rs v rest
855 | _ :: rest
-> fold ls rs rest
861 let findkeyhash c name =
862 try List.assoc
name c.keyhashes
863 with Not_found
-> error
"invalid mode name `%s'" name
868 let h = Hashtbl.create
10 in
869 let dc = { defconf
with angle
= defconf
.angle
} in
870 let rec toplevel v t spos
_ =
872 | Vdata
| Vcdata
| Vend
-> v
873 | Vopen
("llppconfig", _, closed
) ->
876 else { v
with f = llppconfig
}
877 | Vopen
_ -> parse_error
"unexpected subelement at top level" s spos
878 | Vclose
_ -> parse_error
"unexpected close at top level" s spos
880 and llppconfig v t spos
_ =
882 | Vdata
| Vcdata
-> v
883 | Vend
-> parse_error
"unexpected end of input in llppconfig" s spos
884 | Vopen
("defaults", attrs
, closed
) ->
885 let c = config_of dc attrs
in
889 else { v
with f = defaults
}
891 | Vopen
("ui-font", attrs
, closed
) ->
892 let rec getsize size
= function
894 | ("size", v
) :: rest
->
896 fromstring int_of_string spos
"size" v
fstate.fontsize
in
898 | l -> getsize size l
900 fstate.fontsize
<- getsize fstate.fontsize attrs
;
903 else { v
with f = uifont
(Buffer.create
10) }
905 | Vopen
("doc", attrs
, closed
) ->
906 let pathent, key
, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
907 let path = unentS pathent
908 and origin
= unentS origin
909 and pageno = fromstring int_of_string spos
"page" spage
0
910 and rely
= fromstring float_of_string spos
"rely" srely
0.0
911 and pan
= fromstring int_of_string spos
"pan" span
0
912 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
913 let c = config_of dc attrs
in
915 let anchor = (pageno, rely
, visy
) in
917 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
918 else { v
with f = doc
path origin pan
anchor c [] }
920 | Vopen
_ -> parse_error
"unexpected subelement in llppconfig" s spos
921 | Vclose
"llppconfig" -> { v
with f = toplevel }
922 | Vclose
_ -> parse_error
"unexpected close in llppconfig" s spos
924 and defaults v t spos
_ =
926 | Vdata
| Vcdata
-> v
927 | Vend
-> parse_error
"unexpected end of input in defaults" s spos
928 | Vopen
("keymap", attrs
, closed
) ->
930 try List.assoc
"mode" attrs
931 with Not_found
-> "global" in
936 let h = findkeyhash dc modename in
937 KeyMap.iter
(Hashtbl.replace
h) keymap
;
940 { v
with f = pkeymap
ret KeyMap.empty
}
943 parse_error
"unexpected subelement in defaults" s spos
945 | Vclose
"defaults" ->
946 { v
with f = llppconfig
}
948 | Vclose
_ -> parse_error
"unexpected close in defaults" s spos
950 and uifont
b v t spos epos
=
953 Buffer.add_substring
b s spos
(epos
- spos
);
955 | Vopen
(_, _, _) -> parse_error
"unexpected subelement in ui-font" s spos
956 | Vclose
"ui-font" ->
957 if emptystr
!fontpath
958 then fontpath := Buffer.contents
b;
959 { v
with f = llppconfig
}
960 | Vclose
_ -> parse_error
"unexpected close in ui-font" s spos
961 | Vend
-> parse_error
"unexpected end of input in ui-font" s spos
963 and doc
path origin pan
anchor c bookmarks v t spos
_ =
965 | Vdata
| Vcdata
-> v
966 | Vend
-> parse_error
"unexpected end of input in doc" s spos
967 | Vopen
("bookmarks", _, closed
) ->
970 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
972 | Vopen
("keymap", attrs
, closed
) ->
974 try List.assoc
"mode" attrs
975 with Not_found
-> "global"
981 let h = findkeyhash c modename in
982 KeyMap.iter
(Hashtbl.replace
h) keymap
;
983 doc
path origin pan
anchor c bookmarks
985 { v
with f = pkeymap
ret KeyMap.empty
}
987 | Vopen
("css", [], false) ->
988 { v
with f = pcss
path origin pan
anchor c bookmarks
}
991 parse_error
"unexpected subelement in doc" s spos
994 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
995 { v
with f = llppconfig
}
997 | Vclose
_ -> parse_error
"unexpected close in doc" s spos
999 and pcss
path origin pan
anchor c bookmarks v t spos epos
=
1002 let b = Buffer.create
10 in
1003 Buffer.add_substring
b s spos
(epos
- spos
);
1004 { v
with f = pcss
path origin pan
anchor
1005 { c with css
= Buffer.contents
b }
1007 | Vend
-> parse_error
"unexpected end of input in css" s spos
1008 | Vopen
_ -> parse_error
"unexpected subelement in css" s spos
1009 | Vclose
"css" -> { v
with f = doc
path origin pan
anchor c bookmarks
}
1010 | Vclose
_ -> parse_error
"unexpected close in css" s spos
1012 and pkeymap
ret keymap v t spos
_ =
1014 | Vdata
| Vcdata
-> v
1015 | Vend
-> parse_error
"unexpected end of input in keymap" s spos
1016 | Vopen
("map", attrs
, closed
) ->
1017 let r, l = map_of attrs
in
1018 let kss = fromstring keys_of_string spos
"in" r [] in
1019 let lss = fromstring keys_of_string spos
"out" l [] in
1023 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1024 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1027 then { v
with f = pkeymap
ret keymap }
1030 { v
with f = skip
"map" f }
1032 | Vopen
_ -> parse_error
"unexpected subelement in keymap" s spos
1033 | Vclose
"keymap" ->
1034 { v
with f = ret keymap }
1035 | Vclose
_ -> parse_error
"unexpected close in keymap" s spos
1037 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1039 | Vdata
| Vcdata
-> v
1040 | Vend
-> parse_error
"unexpected end of input in bookmarks" s spos
1041 | Vopen
("item", attrs
, closed
) ->
1042 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1043 let page = fromstring int_of_string spos
"page" spage
0
1044 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1045 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1047 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1050 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1053 { v
with f = skip
"item" f }
1055 | Vopen
_ -> parse_error
"unexpected subelement in bookmarks" s spos
1056 | Vclose
"bookmarks" ->
1057 { v
with f = doc
path origin pan
anchor c bookmarks }
1058 | Vclose
_ -> parse_error
"unexpected close in bookmarks" s spos
1060 and skip tag
f v t spos
_ =
1062 | Vdata
| Vcdata
-> v
1064 parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1065 | Vopen
(tag'
, _, closed
) ->
1069 let f'
() = { v
with f = skip tag
f } in
1070 { v
with f = skip tag'
f'
}
1074 else parse_error
("unexpected close in skipped " ^ tag
) s spos
1076 parse
{ f = toplevel; accu
= () } s;
1080 let do_load f contents
=
1083 | Parser.Parse_error
(msg
, s, pos
) ->
1084 let subs = Parser.subs s pos
in
1085 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1087 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1092 let xdgconfdir = Utils.getenvdef
"XDG_CONFIG_HOME" E.s in
1093 if emptystr
xdgconfdir
1096 let dir = Filename.concat
home ".config" in
1097 if Sys.is_directory
dir then dir else home
1101 Filename.concat
dir "llpp.conf"
1104 let confpath = ref defconfpath;;
1106 let load2 f default
=
1107 match filecontents
!confpath with
1108 | contents
-> f @@ do_load get contents
1109 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1110 f (Hashtbl.create
0, defconf
)
1112 dolog
"error loading configuration from `%S': %s" !confpath @@ exntos exn
;
1116 let load1 f = load2 f false;;
1124 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1125 if conf.lastvisit
> besttime
1126 then (path, conf.lastvisit
)
1129 (state.path, -.infinity
)
1133 let pc, pb
, px
, pa
, po
=
1134 let def = dc, [], 0, emptyanchor, state.origin
in
1135 if emptystr
state.path
1138 let absname = abspath
state.path in
1139 match Hashtbl.find h absname with
1140 | (c,b,x
,a
,_) -> (c,b,x
,a
,state.origin
)
1141 | exception Not_found
->
1142 let exception E
of (conf * outline list
* int * anchor * string) in
1143 let key = try Digest.file
absname |> Digest.to_hex
with _ -> E.s in
1147 Hashtbl.iter
(fun p
((c, _, _, _, _) as v
) ->
1150 dolog
"will use %s's settings due to matching keys" p
;
1157 | exception E v
-> v
1161 state.bookmarks <- pb
;
1165 cbput state.hists
.nav pa
;
1173 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1174 (path, pc, pb
, px
, pa
, po
) :: accu
)
1180 let add_attrs bb always
dc c time
=
1182 Buffer.add_string bb
"\n ";
1183 Printf.bprintf bb fmt
s
1185 let o c fmt
s = if c then o' fmt
s else ignore
in
1186 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1187 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1188 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1189 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1190 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1191 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1192 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1193 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1194 and oA
s a
b = o (always
|| a
<> b) "%s='%s'" s (rgba_to_string a
)
1195 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1196 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1197 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1199 o (always
|| a
land m
<> b land m
) "%s='%b'" s (a
land m
!= 0)
1200 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1202 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1207 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1208 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1209 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1214 | Some
c when c > 1 -> o'
"%s='%d'" s c
1217 oi
"width" c.cwinw
dc.cwinw
;
1218 oi
"height" c.cwinh
dc.cwinh
;
1219 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1220 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1221 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb scrollbhv
;
1222 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb scrollbvv
;
1223 ob "case-insensitive-search" c.icase
dc.icase
;
1224 ob "preload" c.preload
dc.preload
;
1225 oi
"page-bias" c.pagebias
dc.pagebias
;
1226 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1227 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1228 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1229 ob "highlight-links" c.hlinks
dc.hlinks
;
1230 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1231 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1232 oz
"zoom" c.zoom dc.zoom;
1233 ob "presentation" c.presentation
dc.presentation
;
1234 oi
"rotation-angle" c.angle
dc.angle
;
1235 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1236 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1237 oi
"tex-count" c.texcount
dc.texcount
;
1238 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1239 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1240 oc
"background-color" c.bgcolor
dc.bgcolor
;
1241 oA
"scrollbar-color" c.sbarcolor
dc.sbarcolor
;
1242 oA
"scrollbar-handle-color" c.sbarhndlcolor
dc.sbarhndlcolor
;
1243 oA
"texture-color" c.texturecolor
dc.texturecolor
;
1244 oi
"tile-width" c.tilew
dc.tilew
;
1245 oi
"tile-height" c.tileh
dc.tileh
;
1246 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1247 ob "checkers" c.checkers
dc.checkers
;
1248 oi
"aalevel" c.aalevel
dc.aalevel
;
1249 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1250 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1251 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1252 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1253 oC
"color-space" c.colorspace
dc.colorspace
;
1254 ob "invert-colors" c.invert
dc.invert
;
1255 oF
"brightness" c.colorscale
dc.colorscale
;
1256 oco
"columns" c.columns
dc.columns
;
1257 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1258 os
"selection-command" c.selcmd
dc.selcmd
;
1259 os
"paste-command" c.pastecmd
dc.pastecmd
;
1260 os
"synctex-command" c.stcmd
dc.stcmd
;
1261 os
"pax-command" c.paxcmd
dc.paxcmd
;
1262 os
"askpass-command" c.passcmd
dc.passcmd
;
1263 os
"savepath-command" c.savecmd
dc.savecmd
;
1264 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1265 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1266 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1267 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1268 ob "use-pbo" c.usepbo
dc.usepbo
;
1269 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1270 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1271 op
"point-and-x" c.pax
dc.pax
;
1272 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1273 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1275 then os
"title" c.title
dc.title
;
1276 oL
"last-visit" (Int64.of_float time
) 0L;
1277 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1278 ob "coarse-presentation-positioning" c.coarseprespos
dc.coarseprespos
;
1279 ob "use-document-css" c.usedoccss
dc.usedoccss
;
1282 let keymapsbuf always
dc c =
1284 let bb = create
16 in
1285 let rec loop = function
1287 | (modename, h) :: rest
->
1288 let dh = findkeyhash dc modename in
1289 if always
|| h <> dh
1291 if Hashtbl.length
h > 0
1293 if length
bb > 0 then add_char
bb '
\n'
;
1294 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1295 Hashtbl.iter
(fun i
o ->
1296 if always
|| match Hashtbl.find dh i
1297 with | dO
-> dO
<> o | exception Not_found
-> false
1300 if Wsi.withctrl m
then add_string
bb "ctrl-";
1301 if Wsi.withalt m
then add_string
bb "alt-";
1302 if Wsi.withshift m
then add_string
bb "shift-";
1303 if Wsi.withmeta m
then add_string
bb "meta-";
1304 add_string
bb (Wsi.keyname
k);
1307 let rec loop = function
1309 | km
:: [] -> addkm km
1310 | km
:: rest
-> addkm km
; add_char
bb ' '
; loop rest
1314 add_string
bb "<map in='";
1318 add_string
bb "' out='"; addkm km
; add_string
bb "'/>\n"
1321 add_string
bb "' out='"; addkms kms
; add_string
bb "'/>\n"
1323 | KMmulti
(ins
, kms
) ->
1324 add_char
bb ' '
; addkms ins
; add_string
bb "' out='";
1325 addkms kms
; add_string
bb "'/>\n"
1327 add_string
bb "</keymap>";
1336 let keystostrlist c =
1337 let rec loop accu
= function
1339 | (modename, h) :: rest
->
1341 if Hashtbl.length
h > 0
1343 let accu = Printf.sprintf
"\xc2\xb7Keys for %s" modename :: accu in
1344 Hashtbl.fold (fun i
o a
->
1345 let bb = Buffer.create
10 in
1347 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1348 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1349 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1350 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1351 Buffer.add_string
bb (Wsi.keyname
k);
1354 let rec loop = function
1356 | km
:: [] -> addkm km
1358 addkm km
; Buffer.add_char
bb ' '
;
1364 Buffer.add_char
bb '
\t'
;
1366 | KMinsrt km
-> addkm km
1367 | KMinsrl kms
-> addkms kms
1368 | KMmulti
(ins
, kms
) ->
1369 Buffer.add_char
bb ' '
;
1371 Buffer.add_string
bb "\t";
1374 Buffer.contents
bb :: a
1384 let save1 bb leavebirdseye x
h dc =
1385 let uifontsize = fstate.fontsize
in
1386 let dc = if conf.bedefault
then conf else dc in
1387 Buffer.add_string
bb "<llppconfig>\n";
1389 if nonemptystr
!fontpath
1390 then Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1395 then Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1398 Buffer.add_string
bb "<defaults";
1399 add_attrs bb true dc dc nan
;
1400 let kb = keymapsbuf true dc dc in
1401 if Buffer.length
kb > 0
1403 Buffer.add_string
bb ">\n";
1404 Buffer.add_buffer
bb kb;
1405 Buffer.add_string
bb "\n</defaults>\n";
1407 else Buffer.add_string
bb "/>\n";
1409 let adddoc path pan
anchor c bookmarks time origin
=
1410 if not
(bookmarks == [] && c = dc && anchor = emptyanchor)
1412 Printf.bprintf
bb "<doc path='%s'"
1413 (Parser.enent
path 0 (String.length
path));
1415 if nonemptystr
c.key
1416 then Printf.bprintf
bb "\n key='%s'" c.key;
1418 if nonemptystr origin
1419 then Printf.bprintf
bb "\n origin='%s'"
1420 (Parser.enent origin
0 (String.length origin
));
1422 if anchor <> emptyanchor
1424 let n, rely
, visy
= anchor in
1425 Printf.bprintf
bb "\n page='%d'" n;
1428 then Printf.bprintf
bb " rely='%f'" rely
;
1430 if abs_float visy
> 1e-6
1431 then Printf.bprintf
bb " visy='%f'" visy
;
1435 then Printf.bprintf
bb " pan='%d'" pan
;
1437 add_attrs bb false dc c time
;
1438 if nonemptystr
c.css
1439 then Printf.bprintf
bb ">\n <css><![CDATA[%s]]></css>" c.css
;
1440 let kb = keymapsbuf false dc c in
1442 begin match bookmarks with
1444 if Buffer.length
kb > 0
1446 Buffer.add_string
bb ">\n";
1447 Buffer.add_buffer
bb kb;
1448 Buffer.add_string
bb "\n</doc>\n";
1451 if nonemptystr
c.css
1452 then Buffer.add_string
bb "\n</doc>\n"
1453 else Buffer.add_string
bb "/>\n"
1456 Buffer.add_string
bb ">\n<bookmarks>\n";
1457 List.iter
(fun (title
, _, kind
) ->
1458 begin match kind
with
1459 | Oanchor
(page, rely
, visy
) ->
1461 "<item title='%s' page='%d'"
1462 (Parser.enent title
0 (String.length title
))
1465 then Printf.bprintf
bb " rely='%f'" rely
;
1466 if abs_float visy
> 1e-6
1467 then Printf.bprintf
bb " visy='%f'" visy
;
1469 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1470 | Oremotedest
_ | Olaunch
_ -> error
"unexpected link in bookmarks"
1472 Buffer.add_string
bb "/>\n";
1474 Buffer.add_string
bb "</bookmarks>";
1475 if Buffer.length
kb > 0
1477 Buffer.add_string
bb "\n";
1478 Buffer.add_buffer
bb kb;
1480 Buffer.add_string
bb "\n</doc>\n";
1486 match state.mode
with
1487 | Birdseye
(c, pan, _, _, _) ->
1489 match conf.columns
with
1490 | Cmulti
((c, _, _), _) -> Some
c
1494 match c.columns
with
1495 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1496 | Csingle
_ -> Csingle
E.a
1497 | Csplit
_ -> failwith
"quit from bird's eye while split"
1499 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1502 | LinkNav
_ -> x
, conf
1504 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1505 if nonemptystr
docpath
1507 adddoc docpath pan (getanchor ())
1509 let autoscrollstep =
1510 match state.autoscroll
with
1512 | None
-> conf.autoscrollstep
1514 begin match state.mode
with
1515 | Birdseye beye
-> leavebirdseye beye
true
1520 let key = try Digest.file
docpath |> Digest.to_hex
1522 { conf with autoscrollstep; key }
1528 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1529 if docpath <> abspath
path
1530 then adddoc path x
anchor c bookmarks c.lastvisit origin
1532 Buffer.add_string
bb "</llppconfig>\n";
1536 let save leavebirdseye
=
1537 let relx = float state.x
/. float state.winw
in
1539 let cx w = truncate
(relx *. float w) in
1541 (fun (w, h, x
) ws
->
1543 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1544 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1545 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1547 (state.winw
, state.winh
, state.x
) state.winstate
1551 let bb = Buffer.create
32768 in
1552 let save2 (h, dc) = save1 bb leavebirdseye x
h dc in
1553 if load1 save2 && Buffer.length
bb > 0
1556 let tmp = !confpath ^
".tmp" in
1557 let oc = open_out_bin
tmp in
1558 Buffer.output_buffer
oc bb;
1560 Unix.rename
tmp !confpath;
1561 with exn
-> dolog
"error saving configuration: %s" @@ exntos exn
1565 let href = ref @@ Hashtbl.create
0 in
1566 let cref = ref defconf
in
1569 if Sys.file_exists
path
1571 else (dolog
"removing entry for '%s'" path; None
) in
1572 Hashtbl.filter_map_inplace
f h;
1577 ignore
(load1 push);
1578 let bb = Buffer.create
32768 in
1579 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1580 if load1 save2 && Buffer.length
bb > 0
1583 let tmp = !confpath ^
".tmp" in
1584 let oc = open_out_bin
tmp in
1585 Buffer.output_buffer
oc bb;
1587 Unix.rename
tmp !confpath;
1588 with exn
-> dolog
"error saving configuration: %s" @@ exntos exn
1592 let logcurrently = function
1593 | Idle
-> dolog
"Idle"
1594 | Loading
(l, gen
) ->
1595 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
1596 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
1597 dolog
"Tiling %d[%d,%d] page=%s cs=%s angle=%d"
1598 l.pageno col row
(~
> pageopaque
)
1599 (CSTE.to_string colorspace
) angle
;
1600 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1601 angle gen
conf.angle
state.gen
1603 conf.tilew
conf.tileh
1604 | Outlining
_ -> dolog
"outlining"
1608 dolog
{|l %d dim
=%d
{
1615 l.pageno l.pagedimno
1619 l.pagedispx
l.pagedispy