Skip to content

Commit

Permalink
Make default font a setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Nov 7, 2023
1 parent 17bab88 commit 64870ba
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Changed:
- Mute SDL startup messages (#2913).
- `int` can optionally raises an error when passing `nan` or `infinity`, `int(infinity)`
now returns `max_int` and `int(-infinity)` returns `min_int`. (#3407)
- Made default font a setting (#3507)
- Changed internal metadata format to be immutable (#3297).
- Allow a getter for the offset of `on_offset` and dropped the metadata
mechanism for updating it (#3355).
Expand Down
1 change: 0 additions & 1 deletion src/core/builtins/builtins_sys.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ let () =
("bindir", "Internal script directory", Configure.bin_dir ());
("rundir", "PID file directory", Configure.rundir ());
("logdir", "logging directory", Configure.logdir ());
("default_font", "default font file", Configure.default_font);
]

(** Liquidsoap stuff *)
Expand Down
10 changes: 9 additions & 1 deletion src/core/configure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ include Liquidsoap_paths
let git_snapshot = git_sha <> None
let requests_max_id = 50
let requests_table_size = 50
let default_font = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"

(** General configuration *)
let conf = Dtools.Conf.void "Liquidsoap configuration"

let conf_default_font =
Dtools.Conf.string
~d:
(match (Sys.os_type, Build_config.system) with
| _, "macosx" -> "/System/Library/Fonts/Times.ttc"
| "Win32", _ -> {|C:\\Windows\WinSxS\calibri.ttf|}
| _ -> "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf")
~p:(conf#plug "default_font") "Default font"

let libs_versions () =
Build_info.V1.Statically_linked_libraries.to_list ()
|> List.map (fun lib ->
Expand Down
4 changes: 1 addition & 3 deletions src/core/configure.mli
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ val conf : Dtools.Conf.ut
val conf_init : Dtools.Conf.ut
val conf_debug : bool Dtools.Conf.t
val conf_debug_errors : bool Dtools.Conf.t
val conf_default_font : string Dtools.Conf.t

(** String describing the OS *)
val host : string
Expand All @@ -26,9 +27,6 @@ val bin_dir : unit -> string
(** Standard path. *)
val path : unit -> string list

(** Default font file *)
val default_font : string

(** Maximal id for a request. *)
val requests_max_id : int

Expand Down
2 changes: 1 addition & 1 deletion src/core/decoder/text/video_text_native.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open Mm
let log = Log.make ["video"; "text"; "native"]

let render_text ~font ~size text =
if font <> Configure.default_font then
if font <> Configure.conf_default_font#get then
log#important "video.text.native does not support custom fonts yet!";
let () = ignore font in
let font = Image.Bitmap.Font.native in
Expand Down
2 changes: 1 addition & 1 deletion src/core/decoder/text/video_text_sdl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let init () =
Sdl_utils.check Tsdl_ttf.Ttf.init ()

let get_font font size =
let font = if font = "" then Configure.default_font else font in
let font = if font = "" then Configure.conf_default_font#get else font in
try Sdl_utils.check (Ttf.open_font font) size
with e ->
raise
Expand Down
4 changes: 2 additions & 2 deletions src/core/sources/video_text.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ let register name init render_text =
Some Lang.null,
Some
(Printf.sprintf "Path to ttf font file (default is `\"%s\"`)."
Configure.default_font) );
Configure.conf_default_font#get) );
("size", Lang.getter_t Lang.int_t, Some (Lang.int 18), Some "Font size.");
( "color",
Lang.getter_t Lang.int_t,
Expand All @@ -113,7 +113,7 @@ let register name init render_text =
let ttf =
List.assoc "font" p |> Lang.to_option
|> Option.map Lang.to_string_getter
|> Option.value ~default:(fun () -> Configure.default_font)
|> Option.value ~default:(fun () -> Configure.conf_default_font#get)
in
let ttf_size = List.assoc "size" p |> Lang.to_int_getter in
let color = List.assoc "color" p |> Lang.to_int_getter in
Expand Down
2 changes: 1 addition & 1 deletion src/libs/liquidsoap.liq
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def liquidsoap.chroot.make(chroot) =

cp(configure.libdir)
cp(configure.bindir)
if file.exists(configure.default_font) then cp(configure.default_font) end
if file.exists(settings.default_font()) then cp(settings.default_font()) end
mkdir(chroot(configure.logdir))
mkdir(chroot(configure.rundir))
cp(liquidsoap.executable)
Expand Down

0 comments on commit 64870ba

Please sign in to comment.