Skip to content

Commit

Permalink
add relocation failsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Dec 24, 2022
1 parent 405bc5c commit 60c1291
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -934,17 +934,21 @@ const FONT_PATHS = Dict{String, String}(
"bold_italic" => FreeTypeAbstraction.get_path(find_and_load_font("TeX Gyre Heros Makie Bold Italic")),
)

function load_font_from_path(str::String)
font = FreeTypeAbstraction.try_load(str)
isnothing(font) && error("Could not load font file $str")
function load_font_from_path(str::String, strict=true)
if (font = FreeTypeAbstraction.try_load(str)) === nothing
strict && error("Could not load font file $str")
end
font
end

function load_font(str::String)
str == "default" && return load_font("TeX Gyre Heros Makie")

font = if (ft_path = get(FONT_PATHS, str, nothing)) !== nothing
load_font_from_path(ft_path)
if (ft = load_font_from_path(ft_path, false)) === nothing
ft = find_and_load_font(str) # can be invalidated on relocation, hard reload
end
ft
elseif isfile(str) # check if the string points to a font file and load that
load_font_from_path(str)
else
Expand Down

0 comments on commit 60c1291

Please sign in to comment.