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 error
"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
= sig
119 val names
: string array
122 module TextEnumMake
(Ten
: TextEnumType
) = struct
123 let names = Ten.names;;
124 let to_int (t
: Ten.t
) = Obj.magic t
;;
125 let to_string t
= names.(to_int t
);;
126 let of_int n
: Ten.t
= Obj.magic n
;;
129 if i
= Array.length
names
130 then error
"invalid %s: %s" Ten.name s
139 module CSTE
= TextEnumMake
(struct
140 type t
= colorspace
;;
141 let name = "colorspace";;
142 let names = [|"rgb"; "bgr"; "gray"|];;
145 module MTE
= TextEnumMake
(struct
148 let names = [|"page"; "block"; "line"; "word"|];;
151 module FMTE
= TextEnumMake
(struct
153 let name = "fitmodel";;
154 let names = [|"width"; "proportional"; "page"|];;
161 | Olaunch
of launchcommand
162 | Oremote
of (filename
* pageno
)
163 | Oremotedest
of (filename
* destname
)
164 | Ohistory
of (filename
* conf
* outline list
* x
* anchor
* filename
)
165 and outline
= (caption
* outlinelevel
* outlinekind
)
166 and outlinelevel
= int
184 type tile
= opaque
* pixmapsize
* elapsed
185 and elapsed
= float;;
186 type pagemapkey
= pageno
* gen
;;
187 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
192 | Loading
of (page
* gen
)
194 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
196 | Outlining
of outline list
199 type mpos
= int * int
201 | Msel
of (mpos
* mpos
)
203 | Mscrolly
| Mscrollx
204 | Mzoom
of (buttonno
* step
* mpos
)
205 | Mzoomrect
of (mpos
* mpos
)
212 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
213 | Textentry
of (textentry
* onleave
)
215 | LinkNav
of linktarget
216 and onleave
= leavetextentrystatus
-> unit
217 and leavetextentrystatus
= | Cancel
| Confirm
218 and helpitem
= string * int * action
221 | Action
of (uioh
-> uioh
)
223 | Ltexact
of (pageno
* direction
)
224 | Ltgendir
of direction
225 | Ltnotready
of (pageno
* direction
)
226 and direction
= int (* -1, 0, 1 *)
227 and textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
228 and onkey
= string -> Keys.t
-> te
229 and ondone
= string -> unit
230 and histcancel
= unit -> unit
231 and onhist
= ((histcmd
-> string) * histcancel
)
232 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
233 and cancelonempty
= bool
238 | TEswitch
of textentry
250 { mutable ss
: Unix.file_descr
251 ; mutable wsfd
: Unix.file_descr
252 ; mutable stderr
: Unix.file_descr
253 ; mutable errmsgs
: Buffer.t
254 ; mutable newerrmsgs
: bool
258 ; mutable anchor
: anchor
259 ; mutable ranchors
: (string * string * anchor
* string) list
261 ; mutable layout
: page list
262 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
263 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
264 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
265 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
266 ; mutable pagecount
: int
267 ; mutable currently
: currently
268 ; mutable mstate
: mstate
269 ; mutable searchpattern
: string
270 ; mutable rects
: (pageno
* rectcolor
* rect
) list
271 ; mutable rects1
: (pageno
* rectcolor
* rect
) list
272 ; prects
: (pageno
, float array
) Hashtbl.t
273 ; mutable text
: string
274 ; mutable winstate
: Wsi.winstate list
275 ; mutable mode
: mode
276 ; mutable uioh
: uioh
277 ; mutable outlines
: outline array
278 ; mutable bookmarks
: outline list
279 ; mutable path
: string
280 ; mutable password
: string
281 ; mutable nameddest
: string
282 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
283 ; mutable memused
: memsize
285 ; mutable autoscroll
: int option
286 ; mutable help
: helpitem array
287 ; mutable docinfo
: (int * string) list
288 ; mutable checkerstexid
: GlTex.texture_id
option
290 ; mutable prevzoom
: (float * int)
291 ; mutable progress
: float
292 ; mutable mpos
: mpos
293 ; mutable keystate
: keystate
294 ; mutable glinks
: bool
295 ; mutable prevcolumns
: (columns
* float) option
298 ; mutable reprf
: (unit -> unit)
299 ; mutable origin
: string
300 ; mutable roam
: (unit -> unit)
301 ; mutable bzoom
: bool
302 ; mutable lnava
: (pageno
* linkno
) option
303 ; mutable slideshow
: int
306 { pat
: string circbuf
307 ; pag
: string circbuf
308 ; nav
: anchor circbuf
309 ; sel
: string circbuf
313 let emptyanchor = (0, 0.0, 0.0);;
314 let emptykeyhash = Hashtbl.create
0;;
315 let noreprf () = ();;
321 method key _ _
= self
322 method multiclick _ _ _ _
= self
323 method button _ _ _ _ _
= self
324 method motion _ _
= self
325 method pmotion _ _
= self
326 method infochanged _
= ()
327 method scrollpw
= (0, nan
, nan
)
328 method scrollph
= (0, nan
, nan
)
329 method modehash
= emptykeyhash
330 method eformsgs
= false
331 method alwaysscrolly
= false
332 method scroll _ _
= self
333 method zoom _ _ _
= ()
336 let platform_to_string = function
337 | Punknown
-> "unknown"
343 let conf = { defconf
with keyhashes
= copykeyhashes defconf
};;
346 { store
= Array.make n v
353 let cbcap b
= Array.length b
.store
;;
355 let cbput ?
(update_rc
=true) b v
=
358 b
.wc
<- (b
.wc
+ 1) mod cap;
361 b
.len
<- min
(b
.len
+ 1) cap;
364 let cbput_dont_update_rc b v
= cbput ~update_rc
:false b v
;;
366 let cbempty b
= b
.len
= 0;;
368 let cbgetg b circular dir
=
372 let rc = b
.rc + dir
in
384 else bound
rc 0 (b
.len
-1)
390 let cbget b
= cbgetg b
false;;
391 let cbgetc b
= cbgetg b
true;;
396 ; stderr
= Unix.stderr
397 ; errmsgs
= Buffer.create
0
402 ; anchor
= emptyanchor
406 ; tilelru
= Queue.create
()
407 ; pagemap
= Hashtbl.create
10
408 ; tilemap
= Hashtbl.create
10
415 ; prects
= Hashtbl.create
1
419 ; searchpattern
= E.s
427 { nav
= cbnew 10 emptyanchor
437 ; checkerstexid
= None
438 ; prevzoom
= (1.0, 0)
457 let d = state.winh
- h
in
458 max
conf.interpagespace
((d + 1) / 2)
461 let rowyh (c
, coverA
, coverB
) b n
=
462 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
464 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
467 let n'
= n - coverA
in
470 let e = min
state.pagecount
(s + c
) in
471 let rec find m miny maxh
= if m
= e then miny
, maxh
else
472 let _, _, y
, (_, _, h
, _) = b
.(m
) in
473 let miny = min
miny y
in
474 let maxh = max
maxh h
in
480 let ((c
, coverA
, coverB
) as cl
), b
=
481 match conf.columns
with
482 | Csplit
(_, b
) | Csingle b
-> (1, 0, 0), b
483 | Cmulti
(c
, b
) -> c
, b
485 if Array.length b
= 0
488 let rec bsearch nmin nmax
=
490 then bound nmin
0 (state.pagecount
-1)
492 let n = (nmax
+ nmin
) / 2 in
493 let vy, h
= rowyh cl b
n in
497 let ips = calcips h
in
499 let y1 = vy + h
+ ips in
503 then 0, vy + h
+ conf.interpagespace
505 let y0 = vy - conf.interpagespace
in
506 y0, y0 + h
+ conf.interpagespace
516 if n < state.pagecount
- coverB
517 then ((n-coverA
)/c
)*c
+ coverA
524 then bsearch (n+1) nmax
525 else bsearch nmin
(n-1)
528 bsearch 0 (state.pagecount
-1);
532 match conf.columns
with
533 | Cmulti
((_, _, _) as cl
, b
) ->
534 if Array.length b
> 0
536 let y, h
= rowyh cl b
(Array.length b
- 1) in
537 y + h
+ (if conf.presentation
then calcips h
else 0)
540 if Array.length b
> 0
542 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
543 y + h
+ (if conf.presentation
then calcips h
else 0)
546 if Array.length b
> 0
548 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
553 let getpageywh pageno
=
554 let pageno = bound
pageno 0 (state.pagecount
-1) in
555 match conf.columns
with
557 if Array.length b
= 0
560 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
568 if Array.length b
= 0
571 let y, h
= rowyh cl b
pageno in
572 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
580 if Array.length b
= 0
584 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
588 let getpageyh pageno =
589 let y,_,h
= getpageywh pageno in
593 let getpagedim pageno =
596 | (n, _, _, _) as pdim
:: rest
->
598 then (if n = pageno then pdim
else ppdim
)
603 f (-1, -1, -1, -1) state.pdims
606 let getpdimno pageno =
610 | (n, _, _, _) :: rest
->
612 then (if n = pageno then np else p
)
620 let getpagey pageno = fst
(getpageyh pageno);;
624 let coloff = l
.pagecol
* l
.pageh
in
625 float (l
.pagey
+ coloff) /. float l
.pageh
632 then float l
.pagedispy
/. float (calcips l
.pageh
)
633 else float l
.pagedispy
/. float conf.interpagespace
636 (l
.pageno, top, dtop)
640 match state.layout
with
641 | l
:: _ -> getanchor1 l
643 let n = page_of_y state.y in
647 let y, h
= getpageyh n in
648 let dy = y - state.y in
652 let ips = calcips h
in
653 float (dy + ips) /. float ips
655 float dy /. float conf.interpagespace
660 let fontpath = ref E.s;;
662 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
665 Map.Make
(struct type t
= (int * int) let compare = compare end);;
668 let l = String.length
s in
669 let b = Buffer.create
l in
670 Parser.unent
b s 0 l;
675 try Sys.getenv
"HOME"
677 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
681 let modifier_of_string = function
682 | "alt" -> Wsi.altmask
683 | "shift" -> Wsi.shiftmask
684 | "ctrl" | "control" -> Wsi.ctrlmask
685 | "meta" -> Wsi.metamask
689 let keys_of_string s =
690 let key_of_string r
s =
691 let elems = Str.full_split r
s in
694 let m1 = modifier_of_string s in
696 then (Wsi.namekey
s, m
)
699 | Str.Delim
s when n land 1 = 0 -> g s
701 | Str.Delim
_ -> (k
, m
)
703 let rec loop n k m
= function
706 let k, m
= f n k m x
in
711 let elems = Str.split
Utils.Re.whitespace
s in
712 List.map
(key_of_string (Str.regexp
"-")) elems
715 let config_of c attrs
=
719 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
720 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
721 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
722 | "preload" -> { c
with preload
= bool_of_string v
}
723 | "page-bias" -> { c
with pagebias
= int_of_string v
}
724 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
725 | "horizontal-scroll-step" ->
726 { c
with hscrollstep
= max
(int_of_string v
) 1 }
727 | "auto-scroll-step" ->
728 { c
with autoscrollstep
= max
0 (int_of_string v
) }
729 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
730 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
731 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
732 | "vertical-margin" ->
733 { c
with interpagespace
= max
0 (int_of_string v
) }
735 let zoom = float_of_string v
/. 100. in
736 let zoom = max
zoom 0.0 in
737 { c
with zoom = zoom }
738 | "presentation" -> { c
with presentation
= bool_of_string v
}
739 | "rotation-angle" -> { c
with angle
= int_of_string v
}
740 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
741 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
742 | "proportional-display" ->
748 { c
with fitmodel
= fm }
749 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
750 | "pixmap-cache-size" ->
751 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
752 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
753 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
754 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
755 | "background-color" -> { c
with bgcolor
= color_of_string v
}
756 | "scrollbar-color" -> { c
with sbarcolor
= rgba_of_string v
}
757 | "scrollbar-handle-color" -> { c
with sbarhndlcolor
= rgba_of_string v
}
758 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
759 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
760 | "mupdf-store-size" ->
761 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
762 | "checkers" -> { c
with checkers
= bool_of_string v
}
763 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
764 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
765 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
766 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
767 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
768 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
769 | "invert-colors" -> { c
with invert
= bool_of_string v
}
770 | "brightness" -> { c
with colorscale
= float_of_string v
}
772 let (n, _, _) as nab
= multicolumns_of_string v
in
774 then { c
with columns
= Csplit
(-n, E.a
) }
775 else { c
with columns
= Cmulti
(nab
, E.a
) }
776 | "birds-eye-columns" ->
777 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
778 | "selection-command" -> { c
with selcmd
= unentS v
}
779 | "synctex-command" -> { c
with stcmd
= unentS v
}
780 | "pax-command" -> { c
with paxcmd
= unentS v
}
781 | "askpass-command" -> { c
with passcmd
= unentS v
}
782 | "savepath-command" -> { c
with savecmd
= unentS v
}
783 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
784 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
785 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
786 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
787 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
788 | "horizontal-scrollbar-visible" ->
791 then c
.scrollb
lor scrollbhv
792 else c
.scrollb
land (lnot scrollbhv
)
794 { c
with scrollb
= b }
795 | "vertical-scrollbar-visible" ->
798 then c
.scrollb
lor scrollbvv
799 else c
.scrollb
land (lnot scrollbvv
)
801 { c
with scrollb
= b }
802 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
808 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
809 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
810 | "title" -> { c
with title
= unentS v
}
811 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
812 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
813 | "coarse-presentation-positioning" ->
814 { c
with coarseprespos
= bool_of_string v
}
815 | "use-document-css" -> { c
with usedoccss
= bool_of_string v
}
818 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
821 let rec fold c
= function
824 let c = apply c k v
in
827 fold { c with keyhashes
= copykeyhashes
c } attrs
;
830 let fromstring f pos
n v
d =
833 dolog
"error processing attribute (%S=%S) at %d\n%s" n v pos
@@ exntos exn
;
837 let bookmark_of attrs
=
838 let rec fold title page rely visy
= function
839 | ("title", v
) :: rest
-> fold v page rely visy rest
840 | ("page", v
) :: rest
-> fold title v rely visy rest
841 | ("rely", v
) :: rest
-> fold title page v visy rest
842 | ("visy", v
) :: rest
-> fold title page rely v rest
843 | _ :: rest
-> fold title page rely visy rest
844 | [] -> title
, page
, rely
, visy
846 fold "invalid" "0" "0" "0" attrs
850 let rec fold path key page rely pan visy origin
= function
851 | ("path", v
) :: rest
-> fold v key page rely pan visy origin rest
852 | ("key", v
) :: rest
-> fold path v page rely pan visy origin rest
853 | ("page", v
) :: rest
-> fold path key v rely pan visy origin rest
854 | ("rely", v
) :: rest
-> fold path key page v pan visy origin rest
855 | ("pan", v
) :: rest
-> fold path key page rely v visy origin rest
856 | ("visy", v
) :: rest
-> fold path key page rely pan v origin rest
857 | ("origin", v
) :: rest
-> fold path key page rely pan visy v rest
858 | _ :: rest
-> fold path key page rely pan visy origin rest
859 | [] -> path
, key
, page
, rely
, pan
, visy
, origin
861 fold E.s E.s "0" "0" "0" "0" E.s attrs
865 let rec fold rs ls
= function
866 | ("out", v
) :: rest
-> fold v ls rest
867 | ("in", v
) :: rest
-> fold rs v rest
868 | _ :: rest
-> fold ls rs rest
874 let findkeyhash c name =
875 try List.assoc
name c.keyhashes
876 with Not_found
-> error
"invalid mode name `%s'" name
881 let h = Hashtbl.create
10 in
882 let dc = { defconf
with angle
= defconf
.angle
} in
883 let rec toplevel v t spos
_ =
885 | Vdata
| Vcdata
| Vend
-> v
886 | Vopen
("llppconfig", _, closed
) ->
889 else { v
with f = llppconfig
}
890 | Vopen
_ -> parse_error
"unexpected subelement at top level" s spos
891 | Vclose
_ -> parse_error
"unexpected close at top level" s spos
893 and llppconfig v t spos
_ =
895 | Vdata
| Vcdata
-> v
896 | Vend
-> parse_error
"unexpected end of input in llppconfig" s spos
897 | Vopen
("defaults", attrs
, closed
) ->
898 let c = config_of dc attrs
in
902 else { v
with f = defaults
}
904 | Vopen
("ui-font", attrs
, closed
) ->
905 let rec getsize size
= function
907 | ("size", v
) :: rest
->
909 fromstring int_of_string spos
"size" v
fstate.fontsize
in
911 | l -> getsize size l
913 fstate.fontsize
<- getsize fstate.fontsize attrs
;
916 else { v
with f = uifont
(Buffer.create
10) }
918 | Vopen
("doc", attrs
, closed
) ->
919 let pathent, key
, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
920 let path = unentS pathent
921 and origin
= unentS origin
922 and pageno = fromstring int_of_string spos
"page" spage
0
923 and rely
= fromstring float_of_string spos
"rely" srely
0.0
924 and pan
= fromstring int_of_string spos
"pan" span
0
925 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
926 let c = config_of dc attrs
in
928 let anchor = (pageno, rely
, visy
) in
930 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
931 else { v
with f = doc
path origin pan
anchor c [] }
934 parse_error
"unexpected subelement in llppconfig" s spos
936 | Vclose
"llppconfig" -> { v
with f = toplevel }
937 | Vclose
_ -> parse_error
"unexpected close in llppconfig" s spos
939 and defaults v t spos
_ =
941 | Vdata
| Vcdata
-> v
942 | Vend
-> parse_error
"unexpected end of input in defaults" s spos
943 | Vopen
("keymap", attrs
, closed
) ->
945 try List.assoc
"mode" attrs
946 with Not_found
-> "global" in
951 let h = findkeyhash dc modename in
952 KeyMap.iter
(Hashtbl.replace
h) keymap
;
955 { v
with f = pkeymap
ret KeyMap.empty
}
958 parse_error
"unexpected subelement in defaults" s spos
960 | Vclose
"defaults" ->
961 { v
with f = llppconfig
}
963 | Vclose
_ -> parse_error
"unexpected close in defaults" s spos
965 and uifont
b v t spos epos
=
968 Buffer.add_substring
b s spos
(epos
- spos
);
971 parse_error
"unexpected subelement in ui-font" s spos
972 | Vclose
"ui-font" ->
973 if emptystr
!fontpath
974 then fontpath := Buffer.contents
b;
975 { v
with f = llppconfig
}
976 | Vclose
_ -> parse_error
"unexpected close in ui-font" s spos
977 | Vend
-> parse_error
"unexpected end of input in ui-font" s spos
979 and doc
path origin pan
anchor c bookmarks v t spos
_ =
981 | Vdata
| Vcdata
-> v
982 | Vend
-> parse_error
"unexpected end of input in doc" s spos
983 | Vopen
("bookmarks", _, closed
) ->
986 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
988 | Vopen
("keymap", attrs
, closed
) ->
990 try List.assoc
"mode" attrs
991 with Not_found
-> "global"
997 let h = findkeyhash c modename in
998 KeyMap.iter
(Hashtbl.replace
h) keymap
;
999 doc
path origin pan
anchor c bookmarks
1001 { v
with f = pkeymap
ret KeyMap.empty
}
1003 | Vopen
("css", [], false) ->
1004 { v
with f = pcss
path origin pan
anchor c bookmarks
}
1006 | Vopen
(_, _, _) ->
1007 parse_error
"unexpected subelement in doc" s spos
1010 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
1011 { v
with f = llppconfig
}
1013 | Vclose
_ -> parse_error
"unexpected close in doc" s spos
1015 and pcss
path origin pan
anchor c bookmarks v t spos epos
=
1018 let b = Buffer.create
10 in
1019 Buffer.add_substring
b s spos
(epos
- spos
);
1020 { v
with f = pcss
path origin pan
anchor
1021 { c with css
= Buffer.contents
b }
1023 | Vend
-> parse_error
"unexpected end of input in css" s spos
1024 | Vopen
_ -> parse_error
"unexpected subelement in css" s spos
1025 | Vclose
"css" -> { v
with f = doc
path origin pan
anchor c bookmarks
}
1026 | Vclose
_ -> parse_error
"unexpected close in css" s spos
1028 and pkeymap
ret keymap v t spos
_ =
1030 | Vdata
| Vcdata
-> v
1031 | Vend
-> parse_error
"unexpected end of input in keymap" s spos
1032 | Vopen
("map", attrs
, closed
) ->
1033 let r, l = map_of attrs
in
1034 let kss = fromstring keys_of_string spos
"in" r [] in
1035 let lss = fromstring keys_of_string spos
"out" l [] in
1039 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1040 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1043 then { v
with f = pkeymap
ret keymap }
1046 { v
with f = skip
"map" f }
1049 parse_error
"unexpected subelement in keymap" s spos
1051 | Vclose
"keymap" ->
1052 { v
with f = ret keymap }
1054 | Vclose
_ -> parse_error
"unexpected close in keymap" s spos
1056 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1058 | Vdata
| Vcdata
-> v
1059 | Vend
-> parse_error
"unexpected end of input in bookmarks" s spos
1060 | Vopen
("item", attrs
, closed
) ->
1061 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1062 let page = fromstring int_of_string spos
"page" spage
0
1063 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1064 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1066 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1069 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1072 { v
with f = skip
"item" f }
1075 parse_error
"unexpected subelement in bookmarks" s spos
1077 | Vclose
"bookmarks" ->
1078 { v
with f = doc
path origin pan
anchor c bookmarks }
1080 | Vclose
_ -> parse_error
"unexpected close in bookmarks" s spos
1082 and skip tag
f v t spos
_ =
1084 | Vdata
| Vcdata
-> v
1086 parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1087 | Vopen
(tag'
, _, closed
) ->
1091 let f'
() = { v
with f = skip tag
f } in
1092 { v
with f = skip tag'
f'
}
1096 else parse_error
("unexpected close in skipped " ^ tag
) s spos
1099 parse
{ f = toplevel; accu
= () } s;
1103 let do_load f contents
=
1106 | Parser.Parse_error
(msg
, s, pos
) ->
1107 let subs = Parser.subs s pos
in
1108 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1110 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1115 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1116 if emptystr
xdgconfdir
1119 let dir = Filename.concat
home ".config" in
1120 if Sys.is_directory
dir then dir else home
1124 Filename.concat
dir "llpp.conf"
1127 let confpath = ref defconfpath;;
1129 let load2 f default
=
1130 match filecontents
!confpath with
1131 | contents
-> f @@ do_load get contents
1132 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1133 f (Hashtbl.create
0, defconf
)
1135 dolog
"error loading configuration from `%S': %s" !confpath @@ exntos exn
;
1139 let load1 f = load2 f false;;
1147 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1148 if conf.lastvisit
> besttime
1149 then (path, conf.lastvisit
)
1152 (state.path, -.infinity
)
1156 let pc, pb
, px
, pa
, po
=
1157 let def = dc, [], 0, emptyanchor, state.origin
in
1158 if emptystr
state.path
1161 let absname = abspath
state.path in
1162 match Hashtbl.find h absname with
1163 | (c,b,x
,a
,_) -> (c,b,x
,a
,state.origin
)
1164 | exception Not_found
->
1165 let exception E
of (conf * outline list
* int * anchor * string) in
1166 let key = try Digest.file
absname |> Digest.to_hex
with _ -> E.s in
1170 Hashtbl.iter
(fun p
((c, _, _, _, _) as v
) ->
1173 dolog
"will use %s's settings due to matching keys" p
;
1180 | exception E v
-> v
1184 state.bookmarks <- pb
;
1188 cbput state.hists
.nav pa
;
1196 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1197 (path, pc, pb
, px
, pa
, po
) :: accu
)
1203 let add_attrs bb always
dc c time
=
1205 Buffer.add_string bb
"\n ";
1206 Printf.bprintf bb fmt
s
1208 let o c fmt
s = if c then o' fmt
s else ignore
in
1209 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1210 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1211 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1212 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1213 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1214 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1215 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1216 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1217 and oA
s a
b = o (always
|| a
<> b) "%s='%s'" s (rgba_to_string a
)
1218 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1219 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1220 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1222 o (always
|| a
land m
<> b land m
) "%s='%b'" s (a
land m
!= 0)
1223 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1225 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1230 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1231 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1232 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1237 | Some
c when c > 1 -> o'
"%s='%d'" s c
1240 oi
"width" c.cwinw
dc.cwinw
;
1241 oi
"height" c.cwinh
dc.cwinh
;
1242 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1243 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1244 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb scrollbhv
;
1245 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb scrollbvv
;
1246 ob "case-insensitive-search" c.icase
dc.icase
;
1247 ob "preload" c.preload
dc.preload
;
1248 oi
"page-bias" c.pagebias
dc.pagebias
;
1249 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1250 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1251 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1252 ob "highlight-links" c.hlinks
dc.hlinks
;
1253 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1254 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1255 oz
"zoom" c.zoom dc.zoom;
1256 ob "presentation" c.presentation
dc.presentation
;
1257 oi
"rotation-angle" c.angle
dc.angle
;
1258 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1259 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1260 oi
"tex-count" c.texcount
dc.texcount
;
1261 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1262 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1263 oc
"background-color" c.bgcolor
dc.bgcolor
;
1264 oA
"scrollbar-color" c.sbarcolor
dc.sbarcolor
;
1265 oA
"scrollbar-handle-color" c.sbarhndlcolor
dc.sbarhndlcolor
;
1266 oi
"tile-width" c.tilew
dc.tilew
;
1267 oi
"tile-height" c.tileh
dc.tileh
;
1268 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1269 ob "checkers" c.checkers
dc.checkers
;
1270 oi
"aalevel" c.aalevel
dc.aalevel
;
1271 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1272 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1273 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1274 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1275 oC
"color-space" c.colorspace
dc.colorspace
;
1276 ob "invert-colors" c.invert
dc.invert
;
1277 oF
"brightness" c.colorscale
dc.colorscale
;
1278 oco
"columns" c.columns
dc.columns
;
1279 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1280 os
"selection-command" c.selcmd
dc.selcmd
;
1281 os
"synctex-command" c.stcmd
dc.stcmd
;
1282 os
"pax-command" c.paxcmd
dc.paxcmd
;
1283 os
"askpass-command" c.passcmd
dc.passcmd
;
1284 os
"savepath-command" c.savecmd
dc.savecmd
;
1285 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1286 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1287 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1288 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1289 ob "use-pbo" c.usepbo
dc.usepbo
;
1290 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1291 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1292 op
"point-and-x" c.pax
dc.pax
;
1293 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1294 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1296 then os
"title" c.title
dc.title
;
1297 oL
"last-visit" (Int64.of_float time
) 0L;
1298 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1299 ob "coarse-presentation-positioning" c.coarseprespos
dc.coarseprespos
;
1300 ob "use-document-css" c.usedoccss
dc.usedoccss
;
1303 let keymapsbuf always
dc c =
1305 let bb = create
16 in
1306 let rec loop = function
1308 | (modename, h) :: rest
->
1309 let dh = findkeyhash dc modename in
1310 if always
|| h <> dh
1312 if Hashtbl.length
h > 0
1314 if length
bb > 0 then add_char
bb '
\n'
;
1315 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1316 Hashtbl.iter
(fun i
o ->
1317 if always
|| match Hashtbl.find dh i
1318 with | dO
-> dO
<> o | exception Not_found
-> false
1321 if Wsi.withctrl m
then add_string
bb "ctrl-";
1322 if Wsi.withalt m
then add_string
bb "alt-";
1323 if Wsi.withshift m
then add_string
bb "shift-";
1324 if Wsi.withmeta m
then add_string
bb "meta-";
1325 add_string
bb (Wsi.keyname
k);
1328 let rec loop = function
1330 | km
:: [] -> addkm km
1331 | km
:: rest
-> addkm km
; add_char
bb ' '
; loop rest
1335 add_string
bb "<map in='";
1339 add_string
bb "' out='"; addkm km
; add_string
bb "'/>\n"
1342 add_string
bb "' out='"; addkms kms
; add_string
bb "'/>\n"
1344 | KMmulti
(ins
, kms
) ->
1345 add_char
bb ' '
; addkms ins
; add_string
bb "' out='";
1346 addkms kms
; add_string
bb "'/>\n"
1348 add_string
bb "</keymap>";
1357 let keystostrlist c =
1358 let rec loop accu
= function
1360 | (modename, h) :: rest
->
1362 if Hashtbl.length
h > 0
1364 let accu = Printf.sprintf
"\xc2\xb7Keys for %s" modename :: accu in
1365 Hashtbl.fold (fun i
o a
->
1366 let bb = Buffer.create
10 in
1368 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1369 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1370 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1371 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1372 Buffer.add_string
bb (Wsi.keyname
k);
1375 let rec loop = function
1377 | km
:: [] -> addkm km
1379 addkm km
; Buffer.add_char
bb ' '
;
1385 Buffer.add_char
bb '
\t'
;
1393 | KMmulti
(ins
, kms
) ->
1394 Buffer.add_char
bb ' '
;
1396 Buffer.add_string
bb "\t";
1399 Buffer.contents
bb :: a
1409 let save1 bb leavebirdseye x
h dc =
1410 let uifontsize = fstate.fontsize
in
1411 let dc = if conf.bedefault
then conf else dc in
1412 Buffer.add_string
bb "<llppconfig>\n";
1414 if nonemptystr
!fontpath
1415 then Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1420 then Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1423 Buffer.add_string
bb "<defaults";
1424 add_attrs bb true dc dc nan
;
1425 let kb = keymapsbuf true dc dc in
1426 if Buffer.length
kb > 0
1428 Buffer.add_string
bb ">\n";
1429 Buffer.add_buffer
bb kb;
1430 Buffer.add_string
bb "\n</defaults>\n";
1432 else Buffer.add_string
bb "/>\n";
1434 let adddoc path pan
anchor c bookmarks time origin
=
1435 if not
(bookmarks == [] && c = dc && anchor = emptyanchor)
1437 Printf.bprintf
bb "<doc path='%s'"
1438 (Parser.enent
path 0 (String.length
path));
1440 if nonemptystr
c.key
1441 then Printf.bprintf
bb "\n key='%s'" c.key;
1443 if nonemptystr origin
1444 then Printf.bprintf
bb "\n origin='%s'"
1445 (Parser.enent origin
0 (String.length origin
));
1447 if anchor <> emptyanchor
1449 let n, rely
, visy
= anchor in
1450 Printf.bprintf
bb "\n page='%d'" n;
1453 then Printf.bprintf
bb " rely='%f'" rely
;
1455 if abs_float visy
> 1e-6
1456 then Printf.bprintf
bb " visy='%f'" visy
;
1460 then Printf.bprintf
bb " pan='%d'" pan
;
1462 add_attrs bb false dc c time
;
1463 if nonemptystr
c.css
1464 then Printf.bprintf
bb ">\n <css><![CDATA[%s]]></css>" c.css
;
1465 let kb = keymapsbuf false dc c in
1467 begin match bookmarks with
1469 if Buffer.length
kb > 0
1471 Buffer.add_string
bb ">\n";
1472 Buffer.add_buffer
bb kb;
1473 Buffer.add_string
bb "\n</doc>\n";
1476 if nonemptystr
c.css
1477 then Buffer.add_string
bb "\n</doc>\n"
1478 else Buffer.add_string
bb "/>\n"
1480 Buffer.add_string
bb ">\n<bookmarks>\n";
1481 List.iter
(fun (title
, _, kind
) ->
1482 begin match kind
with
1483 | Oanchor
(page, rely
, visy
) ->
1485 "<item title='%s' page='%d'"
1486 (Parser.enent title
0 (String.length title
))
1489 then Printf.bprintf
bb " rely='%f'" rely
;
1491 if abs_float visy
> 1e-6
1492 then Printf.bprintf
bb " visy='%f'" visy
;
1493 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1494 | Oremotedest
_ | Olaunch
_ -> error
"unexpected link in bookmarks"
1496 Buffer.add_string
bb "/>\n";
1498 Buffer.add_string
bb "</bookmarks>";
1499 if Buffer.length
kb > 0
1501 Buffer.add_string
bb "\n";
1502 Buffer.add_buffer
bb kb;
1504 Buffer.add_string
bb "\n</doc>\n";
1510 match state.mode
with
1511 | Birdseye
(c, pan, _, _, _) ->
1513 match conf.columns
with
1514 | Cmulti
((c, _, _), _) -> Some
c
1518 match c.columns
with
1519 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1520 | Csingle
_ -> Csingle
E.a
1521 | Csplit
_ -> failwith
"quit from bird's eye while split"
1523 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1526 | LinkNav
_ -> x
, conf
1528 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1529 if nonemptystr
docpath
1531 adddoc docpath pan (getanchor ())
1533 let autoscrollstep =
1534 match state.autoscroll
with
1536 | None
-> conf.autoscrollstep
1538 begin match state.mode
with
1539 | Birdseye beye
-> leavebirdseye beye
true
1544 let key = try Digest.file
docpath |> Digest.to_hex
1546 { conf with autoscrollstep; key }
1552 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1553 if docpath <> abspath
path
1554 then adddoc path x
anchor c bookmarks c.lastvisit origin
1556 Buffer.add_string
bb "</llppconfig>\n";
1560 let save leavebirdseye
=
1561 let relx = float state.x
/. float state.winw
in
1563 let cx w = truncate
(relx *. float w) in
1565 (fun (w, h, x
) ws
->
1567 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1568 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1569 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1571 (state.winw
, state.winh
, state.x
) state.winstate
1575 let bb = Buffer.create
32768 in
1577 save1 bb leavebirdseye x
h dc
1579 if load1 save2 && Buffer.length
bb > 0
1582 let tmp = !confpath ^
".tmp" in
1583 let oc = open_out_bin
tmp in
1584 Buffer.output_buffer
oc bb;
1586 Unix.rename
tmp !confpath;
1588 dolog
"error saving configuration: %s" @@ exntos exn
1592 let href = ref @@ Hashtbl.create
0 in
1593 let cref = ref defconf
in
1596 if Sys.file_exists
path
1598 else (dolog
"removing entry for '%s'" path; None
) in
1599 Hashtbl.filter_map_inplace
f h;
1604 ignore
(load1 push);
1605 let bb = Buffer.create
32768 in
1606 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1607 if load1 save2 && Buffer.length
bb > 0
1610 let tmp = !confpath ^
".tmp" in
1611 let oc = open_out_bin
tmp in
1612 Buffer.output_buffer
oc bb;
1614 Unix.rename
tmp !confpath;
1616 dolog
"error saving configuration: %s" @@ exntos exn
1620 let logcurrently = function
1621 | Idle
-> dolog
"Idle"
1622 | Loading
(l, gen
) ->
1623 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
1624 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
1625 dolog
"Tiling %d[%d,%d] page=%s cs=%s angle=%d"
1626 l.pageno col row
(~
> pageopaque
)
1627 (CSTE.to_string colorspace
) angle
;
1628 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1629 angle gen
conf.angle
state.gen
1631 conf.tilew
conf.tileh
1632 | Outlining
_ -> dolog
"outlining"
1636 dolog
{|l %d dim
=%d
{
1643 l.pageno l.pagedimno
1647 l.pagedispx
l.pagedispy