Skip to content

Commit a018db8

Browse files
authored
Merge pull request #82 from tecosaur/master
Use BaseDirs for locating font directories
2 parents 7630a9d + 9807a13 commit a018db8

File tree

3 files changed

+15
-47
lines changed

3 files changed

+15
-47
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ uuid = "663a7486-cb36-511b-a19d-713bb74d65c9"
33
version = "0.10.6"
44

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

1112
[compat]
13+
BaseDirs = "1"
1214
ColorVectorSpace = "0.8, 0.9, 0.10, 0.11"
1315
Colors = "0.11, 0.12, 0.13"
1416
FreeType = "4"

src/FreeTypeAbstraction.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using Base.Iterators: Repeated, repeated
55
import Base: /, *, ==, @lock
66
import Base.Broadcast: BroadcastStyle, Style, broadcasted
77
using GeometryBasics: StaticVector
8+
using BaseDirs
89

910
include("types.jl")
1011
include("findfonts.jl")
@@ -25,15 +26,24 @@ fontpaths() = valid_fontpaths
2526
function __init__()
2627
ft_init()
2728
atexit(ft_done)
29+
append!(valid_fontpaths, BaseDirs.fonts(existent=true))
30+
@static if Sys.isunix() && !Sys.isapple()
31+
i = firstindex(valid_fontpaths)
32+
while i <= length(valid_fontpaths)
33+
path = valid_fontpaths[i]
34+
if isdir(path)
35+
append!(valid_fontpaths, filter(isdir, readdir(path, join=true)))
36+
end
37+
i += 1
38+
end
39+
end
2840
# This method of finding fonts might not work for exotic platforms,
2941
# so we supply a way to help it with an environment variable.
30-
paths = filter(isdir, _font_paths())
3142
if haskey(ENV, "FREETYPE_ABSTRACTION_FONT_PATH")
3243
path = ENV["FREETYPE_ABSTRACTION_FONT_PATH"]
3344
isdir(path) || error("Path in environment variable FREETYPE_ABSTRACTION_FONT_PATH is not a valid directory!")
34-
push!(paths, path)
45+
push!(valid_fontpaths, path)
3546
end
36-
append!(valid_fontpaths, paths)
3747
end
3848

3949
if Base.VERSION >= v"1.4.2"

src/findfonts.jl

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,3 @@
1-
if Sys.isapple()
2-
function _font_paths()
3-
return [
4-
"/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.
5-
joinpath(homedir(), "Library/Fonts"), # Fonts specific to each user.
6-
"/Network/Library/Fonts", # Fonts shared for users on a network
7-
"/System/Library/Fonts", # System specific fonts
8-
"/System/Library/Fonts/Supplemental", # new location since Catalina
9-
]
10-
end
11-
elseif Sys.iswindows()
12-
function _font_paths()
13-
return [
14-
joinpath(get(ENV, "SYSTEMROOT", "C:\\Windows"), "Fonts"),
15-
joinpath(homedir(), "AppData", "Local", "Microsoft", "Windows", "Fonts"),
16-
]
17-
end
18-
else
19-
function add_recursive(result, path)
20-
for p in readdir(path)
21-
pabs = joinpath(path, p)
22-
if isdir(pabs)
23-
push!(result, pabs)
24-
add_recursive(result, pabs)
25-
end
26-
end
27-
end
28-
function _font_paths()
29-
result = String[]
30-
for p in (
31-
"/usr/share/fonts",
32-
joinpath(homedir(), ".fonts"),
33-
joinpath(homedir(), ".local/share/fonts"),
34-
"/usr/local/share/fonts"
35-
)
36-
if isdir(p)
37-
push!(result, p)
38-
add_recursive(result, p)
39-
end
40-
end
41-
return result
42-
end
43-
end
44-
451
family_name(x::FTFont) = lowercase(x.family_name)
462
style_name(x::FTFont) = lowercase(x.style_name)
473

0 commit comments

Comments
 (0)