Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ uuid = "663a7486-cb36-511b-a19d-713bb74d65c9"
version = "0.10.6"

[deps]
BaseDirs = "18cc8868-cbac-4acf-b575-c8ff214dc66f"
ColorVectorSpace = "c3611d14-8923-5661-9e6a-0046d554d3a4"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
FreeType = "b38be410-82b0-50bf-ab77-7b57e271db43"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"

[compat]
BaseDirs = "1"
ColorVectorSpace = "0.8, 0.9, 0.10, 0.11"
Colors = "0.11, 0.12, 0.13"
FreeType = "4"
Expand Down
16 changes: 13 additions & 3 deletions src/FreeTypeAbstraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Base: /, *, ==, @lock
import Base.Broadcast: BroadcastStyle, Style, broadcasted
using GeometryBasics: StaticVector
using BaseDirs

include("types.jl")
include("findfonts.jl")
Expand All @@ -25,15 +26,24 @@
function __init__()
ft_init()
atexit(ft_done)
append!(valid_fontpaths, BaseDirs.fonts(existent=true))
@static if Sys.isunix() && !Sys.isapple()

Check warning on line 30 in src/FreeTypeAbstraction.jl

View check run for this annotation

Codecov / codecov/patch

src/FreeTypeAbstraction.jl#L30

Added line #L30 was not covered by tests
i = firstindex(valid_fontpaths)
while i <= length(valid_fontpaths)
path = valid_fontpaths[i]
if isdir(path)
append!(valid_fontpaths, filter(isdir, readdir(path, join=true)))
end
i += 1
end
end
# This method of finding fonts might not work for exotic platforms,
# so we supply a way to help it with an environment variable.
paths = filter(isdir, _font_paths())
if haskey(ENV, "FREETYPE_ABSTRACTION_FONT_PATH")
path = ENV["FREETYPE_ABSTRACTION_FONT_PATH"]
isdir(path) || error("Path in environment variable FREETYPE_ABSTRACTION_FONT_PATH is not a valid directory!")
push!(paths, path)
push!(valid_fontpaths, path)
end
append!(valid_fontpaths, paths)
end

if Base.VERSION >= v"1.4.2"
Expand Down
44 changes: 0 additions & 44 deletions src/findfonts.jl
Original file line number Diff line number Diff line change
@@ -1,47 +1,3 @@
if Sys.isapple()
function _font_paths()
return [
"/Library/Fonts", # Additional fonts that can be used by all users. This is generally where fonts go if they are to be used by other applications.
joinpath(homedir(), "Library/Fonts"), # Fonts specific to each user.
"/Network/Library/Fonts", # Fonts shared for users on a network
"/System/Library/Fonts", # System specific fonts
"/System/Library/Fonts/Supplemental", # new location since Catalina
]
end
elseif Sys.iswindows()
function _font_paths()
return [
joinpath(get(ENV, "SYSTEMROOT", "C:\\Windows"), "Fonts"),
joinpath(homedir(), "AppData", "Local", "Microsoft", "Windows", "Fonts"),
]
end
else
function add_recursive(result, path)
for p in readdir(path)
pabs = joinpath(path, p)
if isdir(pabs)
push!(result, pabs)
add_recursive(result, pabs)
end
end
end
function _font_paths()
result = String[]
for p in (
"/usr/share/fonts",
joinpath(homedir(), ".fonts"),
joinpath(homedir(), ".local/share/fonts"),
"/usr/local/share/fonts"
)
if isdir(p)
push!(result, p)
add_recursive(result, p)
end
end
return result
end
end

family_name(x::FTFont) = lowercase(x.family_name)
style_name(x::FTFont) = lowercase(x.style_name)

Expand Down
Loading