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"
345 let conf = { defconf
with keyhashes
= copykeyhashes defconf
};;
348 { store
= Array.make n v
355 let cbcap b
= Array.length b
.store
;;
357 let cbput ?
(update_rc
=true) b v
=
360 b
.wc
<- (b
.wc
+ 1) mod cap;
363 b
.len
<- min
(b
.len
+ 1) cap;
366 let cbput_dont_update_rc b v
= cbput ~update_rc
:false b v
;;
368 let cbempty b
= b
.len
= 0;;
370 let cbgetg b circular dir
=
374 let rc = b
.rc + dir
in
386 else bound
rc 0 (b
.len
-1)
392 let cbget b
= cbgetg b
false;;
393 let cbgetc b
= cbgetg b
true;;
398 ; stderr
= Unix.stderr
399 ; errmsgs
= Buffer.create
0
404 ; anchor
= emptyanchor
408 ; tilelru
= Queue.create
()
409 ; pagemap
= Hashtbl.create
10
410 ; tilemap
= Hashtbl.create
10
417 ; prects
= Hashtbl.create
1
421 ; searchpattern
= E.s
429 { nav
= cbnew 10 emptyanchor
439 ; checkerstexid
= None
440 ; prevzoom
= (1.0, 0)
459 let d = state.winh
- h
in
460 max
conf.interpagespace
((d + 1) / 2)
463 let rowyh (c
, coverA
, coverB
) b n
=
464 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
466 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
469 let n'
= n - coverA
in
472 let e = min
state.pagecount
(s + c
) in
473 let rec find m miny maxh
= if m
= e then miny
, maxh
else
474 let _, _, y
, (_, _, h
, _) = b
.(m
) in
475 let miny = min
miny y
in
476 let maxh = max
maxh h
in
482 let ((c
, coverA
, coverB
) as cl
), b
=
483 match conf.columns
with
484 | Csplit
(_, b
) | Csingle b
-> (1, 0, 0), b
485 | Cmulti
(c
, b
) -> c
, b
487 if Array.length b
= 0
490 let rec bsearch nmin nmax
=
492 then bound nmin
0 (state.pagecount
-1)
494 let n = (nmax
+ nmin
) / 2 in
495 let vy, h
= rowyh cl b
n in
499 let ips = calcips h
in
501 let y1 = vy + h
+ ips in
505 then 0, vy + h
+ conf.interpagespace
507 let y0 = vy - conf.interpagespace
in
508 y0, y0 + h
+ conf.interpagespace
518 if n < state.pagecount
- coverB
519 then ((n-coverA
)/c
)*c
+ coverA
526 then bsearch (n+1) nmax
527 else bsearch nmin
(n-1)
530 bsearch 0 (state.pagecount
-1);
534 match conf.columns
with
535 | Cmulti
((_, _, _) as cl
, b
) ->
536 if Array.length b
> 0
538 let y, h
= rowyh cl b
(Array.length b
- 1) in
539 y + h
+ (if conf.presentation
then calcips h
else 0)
542 if Array.length b
> 0
544 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
545 y + h
+ (if conf.presentation
then calcips h
else 0)
548 if Array.length b
> 0
550 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
555 let getpageywh pageno
=
556 let pageno = bound
pageno 0 (state.pagecount
-1) in
557 match conf.columns
with
559 if Array.length b
= 0
562 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
570 if Array.length b
= 0
573 let y, h
= rowyh cl b
pageno in
574 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
582 if Array.length b
= 0
586 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
590 let getpageyh pageno =
591 let y,_,h
= getpageywh pageno in
595 let getpagedim pageno =
598 | (n, _, _, _) as pdim
:: rest
->
600 then (if n = pageno then pdim
else ppdim
)
605 f (-1, -1, -1, -1) state.pdims
608 let getpdimno pageno =
612 | (n, _, _, _) :: rest
->
614 then (if n = pageno then np else p
)
622 let getpagey pageno = fst
(getpageyh pageno);;
626 let coloff = l
.pagecol
* l
.pageh
in
627 float (l
.pagey
+ coloff) /. float l
.pageh
635 then float l
.pagedispy
/. float (calcips l
.pageh
)
636 else float l
.pagedispy
/. float conf.interpagespace
639 (l
.pageno, top, dtop)
643 match state.layout
with
644 | l
:: _ -> getanchor1 l
646 let n = page_of_y state.y in
650 let y, h
= getpageyh n in
651 let dy = y - state.y in
655 let ips = calcips h
in
656 float (dy + ips) /. float ips
658 float dy /. float conf.interpagespace
663 let fontpath = ref E.s;;
665 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
668 Map.Make
(struct type t
= (int * int) let compare = compare end);;
671 let l = String.length
s in
672 let b = Buffer.create
l in
673 Parser.unent
b s 0 l;
678 try Sys.getenv
"HOME"
680 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
684 let modifier_of_string = function
685 | "alt" -> Wsi.altmask
686 | "shift" -> Wsi.shiftmask
687 | "ctrl" | "control" -> Wsi.ctrlmask
688 | "meta" -> Wsi.metamask
692 let keys_of_string s =
693 let key_of_string r
s =
694 let elems = Str.full_split r
s in
697 let m1 = modifier_of_string s in
699 then (Wsi.namekey
s, m
)
702 | Str.Delim
s when n land 1 = 0 -> g s
704 | Str.Delim
_ -> (k
, m
)
706 let rec loop n k m
= function
709 let k, m
= f n k m x
in
714 let elems = Str.split
Utils.Re.whitespace
s in
715 List.map
(key_of_string (Str.regexp
"-")) elems
718 let config_of c attrs
=
722 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
723 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
724 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
725 | "preload" -> { c
with preload
= bool_of_string v
}
726 | "page-bias" -> { c
with pagebias
= int_of_string v
}
727 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
728 | "horizontal-scroll-step" ->
729 { c
with hscrollstep
= max
(int_of_string v
) 1 }
730 | "auto-scroll-step" ->
731 { c
with autoscrollstep
= max
0 (int_of_string v
) }
732 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
733 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
734 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
735 | "vertical-margin" ->
736 { c
with interpagespace
= max
0 (int_of_string v
) }
738 let zoom = float_of_string v
/. 100. in
739 let zoom = max
zoom 0.0 in
740 { c
with zoom = zoom }
741 | "presentation" -> { c
with presentation
= bool_of_string v
}
742 | "rotation-angle" -> { c
with angle
= int_of_string v
}
743 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
744 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
745 | "proportional-display" ->
751 { c
with fitmodel
= fm }
752 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
753 | "pixmap-cache-size" ->
754 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
755 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
756 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
757 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
758 | "background-color" -> { c
with bgcolor
= color_of_string v
}
759 | "scrollbar-color" -> { c
with sbarcolor
= rgba_of_string v
}
760 | "scrollbar-handle-color" -> { c
with sbarhndlcolor
= rgba_of_string v
}
761 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
762 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
763 | "mupdf-store-size" ->
764 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
765 | "checkers" -> { c
with checkers
= bool_of_string v
}
766 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
767 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
768 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
769 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
770 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
771 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
772 | "invert-colors" -> { c
with invert
= bool_of_string v
}
773 | "brightness" -> { c
with colorscale
= float_of_string v
}
775 let (n, _, _) as nab
= multicolumns_of_string v
in
777 then { c
with columns
= Csplit
(-n, E.a
) }
778 else { c
with columns
= Cmulti
(nab
, E.a
) }
779 | "birds-eye-columns" ->
780 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
781 | "selection-command" -> { c
with selcmd
= unentS v
}
782 | "synctex-command" -> { c
with stcmd
= unentS v
}
783 | "pax-command" -> { c
with paxcmd
= unentS v
}
784 | "askpass-command" -> { c
with passcmd
= unentS v
}
785 | "savepath-command" -> { c
with savecmd
= unentS v
}
786 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
787 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
788 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
789 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
790 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
791 | "horizontal-scrollbar-visible" ->
794 then c
.scrollb
lor scrollbhv
795 else c
.scrollb
land (lnot scrollbhv
)
797 { c
with scrollb
= b }
798 | "vertical-scrollbar-visible" ->
801 then c
.scrollb
lor scrollbvv
802 else c
.scrollb
land (lnot scrollbvv
)
804 { c
with scrollb
= b }
805 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
811 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
812 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
813 | "title" -> { c
with title
= unentS v
}
814 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
815 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
816 | "coarse-presentation-positioning" ->
817 { c
with coarseprespos
= bool_of_string v
}
818 | "use-document-css" -> { c
with usedoccss
= bool_of_string v
}
821 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
824 let rec fold c
= function
827 let c = apply c k v
in
830 fold { c with keyhashes
= copykeyhashes
c } attrs
;
833 let fromstring f pos
n v
d =
836 dolog
"error processing attribute (%S=%S) at %d\n%s" n v pos
@@ exntos exn
;
840 let bookmark_of attrs
=
841 let rec fold title page rely visy
= function
842 | ("title", v
) :: rest
-> fold v page rely visy rest
843 | ("page", v
) :: rest
-> fold title v rely visy rest
844 | ("rely", v
) :: rest
-> fold title page v visy rest
845 | ("visy", v
) :: rest
-> fold title page rely v rest
846 | _ :: rest
-> fold title page rely visy rest
847 | [] -> title
, page
, rely
, visy
849 fold "invalid" "0" "0" "0" attrs
853 let rec fold path key page rely pan visy origin
= function
854 | ("path", v
) :: rest
-> fold v key page rely pan visy origin rest
855 | ("key", v
) :: rest
-> fold path v page rely pan visy origin rest
856 | ("page", v
) :: rest
-> fold path key v rely pan visy origin rest
857 | ("rely", v
) :: rest
-> fold path key page v pan visy origin rest
858 | ("pan", v
) :: rest
-> fold path key page rely v visy origin rest
859 | ("visy", v
) :: rest
-> fold path key page rely pan v origin rest
860 | ("origin", v
) :: rest
-> fold path key page rely pan visy v rest
861 | _ :: rest
-> fold path key page rely pan visy origin rest
862 | [] -> path
, key
, page
, rely
, pan
, visy
, origin
864 fold E.s E.s "0" "0" "0" "0" E.s attrs
868 let rec fold rs ls
= function
869 | ("out", v
) :: rest
-> fold v ls rest
870 | ("in", v
) :: rest
-> fold rs v rest
871 | _ :: rest
-> fold ls rs rest
877 let findkeyhash c name =
878 try List.assoc
name c.keyhashes
879 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
884 let h = Hashtbl.create
10 in
885 let dc = { defconf
with angle
= defconf
.angle
} in
886 let rec toplevel v t spos
_ =
888 | Vdata
| Vcdata
| Vend
-> v
889 | Vopen
("llppconfig", _, closed
) ->
892 else { v
with f = llppconfig
}
893 | Vopen
_ -> parse_error
"unexpected subelement at top level" s spos
894 | Vclose
_ -> parse_error
"unexpected close at top level" s spos
896 and llppconfig v t spos
_ =
898 | Vdata
| Vcdata
-> v
899 | Vend
-> parse_error
"unexpected end of input in llppconfig" s spos
900 | Vopen
("defaults", attrs
, closed
) ->
901 let c = config_of dc attrs
in
905 else { v
with f = defaults
}
907 | Vopen
("ui-font", attrs
, closed
) ->
908 let rec getsize size
= function
910 | ("size", v
) :: rest
->
912 fromstring int_of_string spos
"size" v
fstate.fontsize
in
914 | l -> getsize size l
916 fstate.fontsize
<- getsize fstate.fontsize attrs
;
919 else { v
with f = uifont
(Buffer.create
10) }
921 | Vopen
("doc", attrs
, closed
) ->
922 let pathent, key
, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
923 let path = unentS pathent
924 and origin
= unentS origin
925 and pageno = fromstring int_of_string spos
"page" spage
0
926 and rely
= fromstring float_of_string spos
"rely" srely
0.0
927 and pan
= fromstring int_of_string spos
"pan" span
0
928 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
929 let c = config_of dc attrs
in
931 let anchor = (pageno, rely
, visy
) in
933 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
934 else { v
with f = doc
path origin pan
anchor c [] }
937 parse_error
"unexpected subelement in llppconfig" s spos
939 | Vclose
"llppconfig" -> { v
with f = toplevel }
940 | Vclose
_ -> parse_error
"unexpected close in llppconfig" s spos
942 and defaults v t spos
_ =
944 | Vdata
| Vcdata
-> v
945 | Vend
-> parse_error
"unexpected end of input in defaults" s spos
946 | Vopen
("keymap", attrs
, closed
) ->
948 try List.assoc
"mode" attrs
949 with Not_found
-> "global" in
954 let h = findkeyhash dc modename in
955 KeyMap.iter
(Hashtbl.replace
h) keymap
;
958 { v
with f = pkeymap
ret KeyMap.empty
}
961 parse_error
"unexpected subelement in defaults" s spos
963 | Vclose
"defaults" ->
964 { v
with f = llppconfig
}
966 | Vclose
_ -> parse_error
"unexpected close in defaults" s spos
968 and uifont
b v t spos epos
=
971 Buffer.add_substring
b s spos
(epos
- spos
);
974 parse_error
"unexpected subelement in ui-font" s spos
975 | Vclose
"ui-font" ->
976 if emptystr
!fontpath
977 then fontpath := Buffer.contents
b;
978 { v
with f = llppconfig
}
979 | Vclose
_ -> parse_error
"unexpected close in ui-font" s spos
980 | Vend
-> parse_error
"unexpected end of input in ui-font" s spos
982 and doc
path origin pan
anchor c bookmarks v t spos
_ =
984 | Vdata
| Vcdata
-> v
985 | Vend
-> parse_error
"unexpected end of input in doc" s spos
986 | Vopen
("bookmarks", _, closed
) ->
989 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
991 | Vopen
("keymap", attrs
, closed
) ->
993 try List.assoc
"mode" attrs
994 with Not_found
-> "global"
1000 let h = findkeyhash c modename in
1001 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1002 doc
path origin pan
anchor c bookmarks
1004 { v
with f = pkeymap
ret KeyMap.empty
}
1006 | Vopen
("css", [], false) ->
1007 { v
with f = pcss
path origin pan
anchor c bookmarks
}
1009 | Vopen
(_, _, _) ->
1010 parse_error
"unexpected subelement in doc" s spos
1013 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
1014 { v
with f = llppconfig
}
1016 | Vclose
_ -> parse_error
"unexpected close in doc" s spos
1018 and pcss
path origin pan
anchor c bookmarks v t spos epos
=
1021 let b = Buffer.create
10 in
1022 Buffer.add_substring
b s spos
(epos
- spos
);
1023 { v
with f = pcss
path origin pan
anchor
1024 { c with css
= Buffer.contents
b }
1026 | Vend
-> parse_error
"unexpected end of input in css" s spos
1027 | Vopen
_ -> parse_error
"unexpected subelement in css" s spos
1028 | Vclose
"css" -> { v
with f = doc
path origin pan
anchor c bookmarks
}
1029 | Vclose
_ -> parse_error
"unexpected close in css" s spos
1031 and pkeymap
ret keymap v t spos
_ =
1033 | Vdata
| Vcdata
-> v
1034 | Vend
-> parse_error
"unexpected end of input in keymap" s spos
1035 | Vopen
("map", attrs
, closed
) ->
1036 let r, l = map_of attrs
in
1037 let kss = fromstring keys_of_string spos
"in" r [] in
1038 let lss = fromstring keys_of_string spos
"out" l [] in
1042 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1043 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1046 then { v
with f = pkeymap
ret keymap }
1049 { v
with f = skip
"map" f }
1052 parse_error
"unexpected subelement in keymap" s spos
1054 | Vclose
"keymap" ->
1055 { v
with f = ret keymap }
1057 | Vclose
_ -> parse_error
"unexpected close in keymap" s spos
1059 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1061 | Vdata
| Vcdata
-> v
1062 | Vend
-> parse_error
"unexpected end of input in bookmarks" s spos
1063 | Vopen
("item", attrs
, closed
) ->
1064 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1065 let page = fromstring int_of_string spos
"page" spage
0
1066 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1067 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1069 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1072 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1075 { v
with f = skip
"item" f }
1078 parse_error
"unexpected subelement in bookmarks" s spos
1080 | Vclose
"bookmarks" ->
1081 { v
with f = doc
path origin pan
anchor c bookmarks }
1083 | Vclose
_ -> parse_error
"unexpected close in bookmarks" s spos
1085 and skip tag
f v t spos
_ =
1087 | Vdata
| Vcdata
-> v
1089 parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1090 | Vopen
(tag'
, _, closed
) ->
1094 let f'
() = { v
with f = skip tag
f } in
1095 { v
with f = skip tag'
f'
}
1099 else parse_error
("unexpected close in skipped " ^ tag
) s spos
1102 parse
{ f = toplevel; accu
= () } s;
1106 let do_load f contents
=
1109 | Parser.Parse_error
(msg
, s, pos
) ->
1110 let subs = Parser.subs s pos
in
1111 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1113 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1118 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1119 if emptystr
xdgconfdir
1122 let dir = Filename.concat
home ".config" in
1123 if Sys.is_directory
dir then dir else home
1127 Filename.concat
dir "llpp.conf"
1130 let confpath = ref defconfpath;;
1132 let load2 f default
=
1133 match filecontents
!confpath with
1134 | contents
-> f @@ do_load get contents
1135 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1136 f (Hashtbl.create
0, defconf
)
1138 dolog
"error loading configuration from `%S': %s" !confpath @@ exntos exn
;
1142 let load1 f = load2 f false;;
1150 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1151 if conf.lastvisit
> besttime
1152 then (path, conf.lastvisit
)
1155 (state.path, -.infinity
)
1159 let pc, pb
, px
, pa
, po
=
1160 let def = dc, [], 0, emptyanchor, state.origin
in
1161 if emptystr
state.path
1164 let absname = abspath
state.path in
1165 match Hashtbl.find h absname with
1166 | (c,b,x
,a
,_) -> (c,b,x
,a
,state.origin
)
1167 | exception Not_found
->
1168 let exception E
of (conf * outline list
* int * anchor * string) in
1169 let key = try Digest.file
absname |> Digest.to_hex
with _ -> E.s in
1174 Hashtbl.iter
(fun p
((c, _, _, _, _) as v
) ->
1177 dolog
"will use %s's settings due to matching keys" p
;
1184 | exception E v
-> v
1188 state.bookmarks <- pb
;
1192 cbput state.hists
.nav pa
;
1200 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1201 (path, pc, pb
, px
, pa
, po
) :: accu
)
1207 let add_attrs bb always
dc c time
=
1209 Buffer.add_string bb
"\n ";
1210 Printf.bprintf bb fmt
s
1212 let o c fmt
s = if c then o' fmt
s else ignore
in
1213 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1214 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1215 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1216 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1217 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1218 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1219 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1220 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1221 and oA
s a
b = o (always
|| a
<> b) "%s='%s'" s (rgba_to_string a
)
1222 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1223 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1224 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1226 o (always
|| a
land m
<> b land m
) "%s='%b'" s (a
land m
!= 0)
1227 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1229 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1234 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1235 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1236 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1241 | Some
c when c > 1 -> o'
"%s='%d'" s c
1244 oi
"width" c.cwinw
dc.cwinw
;
1245 oi
"height" c.cwinh
dc.cwinh
;
1246 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1247 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1248 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb scrollbhv
;
1249 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb scrollbvv
;
1250 ob "case-insensitive-search" c.icase
dc.icase
;
1251 ob "preload" c.preload
dc.preload
;
1252 oi
"page-bias" c.pagebias
dc.pagebias
;
1253 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1254 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1255 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1256 ob "highlight-links" c.hlinks
dc.hlinks
;
1257 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1258 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1259 oz
"zoom" c.zoom dc.zoom;
1260 ob "presentation" c.presentation
dc.presentation
;
1261 oi
"rotation-angle" c.angle
dc.angle
;
1262 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1263 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1264 oi
"tex-count" c.texcount
dc.texcount
;
1265 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1266 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1267 oc
"background-color" c.bgcolor
dc.bgcolor
;
1268 oA
"scrollbar-color" c.sbarcolor
dc.sbarcolor
;
1269 oA
"scrollbar-handle-color" c.sbarhndlcolor
dc.sbarhndlcolor
;
1270 oi
"tile-width" c.tilew
dc.tilew
;
1271 oi
"tile-height" c.tileh
dc.tileh
;
1272 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1273 ob "checkers" c.checkers
dc.checkers
;
1274 oi
"aalevel" c.aalevel
dc.aalevel
;
1275 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1276 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1277 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1278 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1279 oC
"color-space" c.colorspace
dc.colorspace
;
1280 ob "invert-colors" c.invert
dc.invert
;
1281 oF
"brightness" c.colorscale
dc.colorscale
;
1282 oco
"columns" c.columns
dc.columns
;
1283 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1284 os
"selection-command" c.selcmd
dc.selcmd
;
1285 os
"synctex-command" c.stcmd
dc.stcmd
;
1286 os
"pax-command" c.paxcmd
dc.paxcmd
;
1287 os
"askpass-command" c.passcmd
dc.passcmd
;
1288 os
"savepath-command" c.savecmd
dc.savecmd
;
1289 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1290 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1291 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1292 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1293 ob "use-pbo" c.usepbo
dc.usepbo
;
1294 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1295 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1296 op
"point-and-x" c.pax
dc.pax
;
1297 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1298 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1300 then os
"title" c.title
dc.title
;
1301 oL
"last-visit" (Int64.of_float time
) 0L;
1302 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1303 ob "coarse-presentation-positioning" c.coarseprespos
dc.coarseprespos
;
1304 ob "use-document-css" c.usedoccss
dc.usedoccss
;
1307 let keymapsbuf always
dc c =
1309 let bb = create
16 in
1310 let rec loop = function
1312 | (modename, h) :: rest
->
1313 let dh = findkeyhash dc modename in
1314 if always
|| h <> dh
1316 if Hashtbl.length
h > 0
1318 if length
bb > 0 then add_char
bb '
\n'
;
1319 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1320 Hashtbl.iter
(fun i
o ->
1321 if always
|| match Hashtbl.find dh i
1322 with | dO
-> dO
<> o | exception Not_found
-> false
1325 if Wsi.withctrl m
then add_string
bb "ctrl-";
1326 if Wsi.withalt m
then add_string
bb "alt-";
1327 if Wsi.withshift m
then add_string
bb "shift-";
1328 if Wsi.withmeta m
then add_string
bb "meta-";
1329 add_string
bb (Wsi.keyname
k);
1332 let rec loop = function
1334 | km
:: [] -> addkm km
1335 | km
:: rest
-> addkm km
; add_char
bb ' '
; loop rest
1339 add_string
bb "<map in='";
1343 add_string
bb "' out='"; addkm km
; add_string
bb "'/>\n"
1346 add_string
bb "' out='"; addkms kms
; add_string
bb "'/>\n"
1348 | KMmulti
(ins
, kms
) ->
1349 add_char
bb ' '
; addkms ins
; add_string
bb "' out='";
1350 addkms kms
; add_string
bb "'/>\n"
1352 add_string
bb "</keymap>";
1361 let keystostrlist c =
1362 let rec loop accu
= function
1364 | (modename, h) :: rest
->
1366 if Hashtbl.length
h > 0
1368 let accu = Printf.sprintf
"\xc2\xb7Keys for %s" modename :: accu in
1369 Hashtbl.fold (fun i
o a
->
1370 let bb = Buffer.create
10 in
1372 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1373 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1374 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1375 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1376 Buffer.add_string
bb (Wsi.keyname
k);
1379 let rec loop = function
1381 | km
:: [] -> addkm km
1383 addkm km
; Buffer.add_char
bb ' '
;
1389 Buffer.add_char
bb '
\t'
;
1397 | KMmulti
(ins
, kms
) ->
1398 Buffer.add_char
bb ' '
;
1400 Buffer.add_string
bb "\t";
1403 Buffer.contents
bb :: a
1413 let save1 bb leavebirdseye x
h dc =
1414 let uifontsize = fstate.fontsize
in
1415 let dc = if conf.bedefault
then conf else dc in
1416 Buffer.add_string
bb "<llppconfig>\n";
1418 if nonemptystr
!fontpath
1420 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1426 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1429 Buffer.add_string
bb "<defaults";
1430 add_attrs bb true dc dc nan
;
1431 let kb = keymapsbuf true dc dc in
1432 if Buffer.length
kb > 0
1434 Buffer.add_string
bb ">\n";
1435 Buffer.add_buffer
bb kb;
1436 Buffer.add_string
bb "\n</defaults>\n";
1438 else Buffer.add_string
bb "/>\n";
1440 let adddoc path pan
anchor c bookmarks time origin
=
1441 if bookmarks == [] && c = dc && anchor = emptyanchor
1444 Printf.bprintf
bb "<doc path='%s'"
1445 (Parser.enent
path 0 (String.length
path));
1447 if nonemptystr
c.key
1449 Printf.bprintf
bb "\n key='%s'" c.key;
1451 if nonemptystr origin
1452 then Printf.bprintf
bb "\n origin='%s'"
1453 (Parser.enent origin
0 (String.length origin
));
1455 if anchor <> emptyanchor
1457 let n, rely
, visy
= anchor in
1458 Printf.bprintf
bb "\n page='%d'" n;
1461 then Printf.bprintf
bb " rely='%f'" rely
;
1463 if abs_float visy
> 1e-6
1464 then Printf.bprintf
bb " visy='%f'" visy
;
1468 then Printf.bprintf
bb " pan='%d'" pan
;
1470 add_attrs bb false dc c time
;
1471 if nonemptystr
c.css
1472 then Printf.bprintf
bb ">\n <css><![CDATA[%s]]></css>" c.css
;
1473 let kb = keymapsbuf false dc c in
1475 begin match bookmarks with
1477 if Buffer.length
kb > 0
1479 Buffer.add_string
bb ">\n";
1480 Buffer.add_buffer
bb kb;
1481 Buffer.add_string
bb "\n</doc>\n";
1484 if nonemptystr
c.css
1485 then Buffer.add_string
bb "\n</doc>\n"
1486 else Buffer.add_string
bb "/>\n"
1488 Buffer.add_string
bb ">\n<bookmarks>\n";
1489 List.iter
(fun (title
, _, kind
) ->
1490 begin match kind
with
1491 | Oanchor
(page, rely
, visy
) ->
1493 "<item title='%s' page='%d'"
1494 (Parser.enent title
0 (String.length title
))
1499 Printf.bprintf
bb " rely='%f'" rely
1501 if abs_float visy
> 1e-6
1503 Printf.bprintf
bb " visy='%f'" visy
1505 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1506 | Oremotedest
_ | Olaunch
_ ->
1507 failwith
"unexpected link in bookmarks"
1509 Buffer.add_string
bb "/>\n";
1511 Buffer.add_string
bb "</bookmarks>";
1512 if Buffer.length
kb > 0
1514 Buffer.add_string
bb "\n";
1515 Buffer.add_buffer
bb kb;
1517 Buffer.add_string
bb "\n</doc>\n";
1523 match state.mode
with
1524 | Birdseye
(c, pan, _, _, _) ->
1526 match conf.columns
with
1527 | Cmulti
((c, _, _), _) -> Some
c
1531 match c.columns
with
1532 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1533 | Csingle
_ -> Csingle
E.a
1534 | Csplit
_ -> failwith
"quit from bird's eye while split"
1536 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1539 | LinkNav
_ -> x
, conf
1541 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1542 if nonemptystr
docpath
1544 adddoc docpath pan (getanchor ())
1546 let autoscrollstep =
1547 match state.autoscroll
with
1549 | None
-> conf.autoscrollstep
1551 begin match state.mode
with
1552 | Birdseye beye
-> leavebirdseye beye
true
1557 let key = try Digest.file
docpath |> Digest.to_hex
1559 { conf with autoscrollstep; key }
1565 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1566 if docpath <> abspath
path
1567 then adddoc path x
anchor c bookmarks c.lastvisit origin
1569 Buffer.add_string
bb "</llppconfig>\n";
1573 let save leavebirdseye
=
1574 let relx = float state.x
/. float state.winw
in
1576 let cx w = truncate
(relx *. float w) in
1578 (fun (w, h, x
) ws
->
1580 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1581 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1582 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1584 (state.winw
, state.winh
, state.x
) state.winstate
1588 let bb = Buffer.create
32768 in
1590 save1 bb leavebirdseye x
h dc
1592 if load1 save2 && Buffer.length
bb > 0
1595 let tmp = !confpath ^
".tmp" in
1596 let oc = open_out_bin
tmp in
1597 Buffer.output_buffer
oc bb;
1599 Unix.rename
tmp !confpath;
1601 dolog
"error saving configuration: %s" @@ exntos exn
1605 let href = ref @@ Hashtbl.create
0 in
1606 let cref = ref defconf
in
1609 if Sys.file_exists
path
1611 else (dolog
"removing entry for '%s'" path; None
) in
1612 Hashtbl.filter_map_inplace
f h;
1617 ignore
(load1 push);
1618 let bb = Buffer.create
32768 in
1619 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1620 if load1 save2 && Buffer.length
bb > 0
1623 let tmp = !confpath ^
".tmp" in
1624 let oc = open_out_bin
tmp in
1625 Buffer.output_buffer
oc bb;
1627 Unix.rename
tmp !confpath;
1629 dolog
"error saving configuration: %s" @@ exntos exn
1633 let logcurrently = function
1634 | Idle
-> dolog
"Idle"
1635 | Loading
(l, gen
) ->
1636 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
1637 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
1638 dolog
"Tiling %d[%d,%d] page=%s cs=%s angle=%d"
1639 l.pageno col row
(~
> pageopaque
)
1640 (CSTE.to_string colorspace
) angle
;
1641 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1642 angle gen
conf.angle
state.gen
1644 conf.tilew
conf.tileh
1645 | Outlining
_ -> dolog
"outlining"
1649 dolog
{|l %d dim
=%d
{
1656 l.pageno l.pagedimno
1660 l.pagedispx
l.pagedispy