-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathfontdirs_unix.go
42 lines (36 loc) · 1.09 KB
/
fontdirs_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//go:build unix && !darwin
// Copyright 2016 Florian Pigorsch. All rights reserved.
//
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package findfont
import (
"os"
"path/filepath"
"runtime"
)
func getFontDirectories() (paths []string) {
switch runtime.GOOS {
case "android":
return []string{"/system/fonts"}
default:
directories := getUserFontDirs()
directories = append(directories, getSystemFontDirs()...)
return directories
}
}
func getUserFontDirs() (paths []string) {
if dataPath := os.Getenv("XDG_DATA_HOME"); dataPath != "" {
return []string{expandUser("~/.fonts/"), filepath.Join(expandUser(dataPath), "fonts")}
}
return []string{expandUser("~/.fonts/"), expandUser("~/.local/share/fonts/")}
}
func getSystemFontDirs() (paths []string) {
if dataPaths := os.Getenv("XDG_DATA_DIRS"); dataPaths != "" {
for _, dataPath := range filepath.SplitList(dataPaths) {
paths = append(paths, filepath.Join(expandUser(dataPath), "fonts"))
}
return paths
}
return []string{"/usr/local/share/fonts/", "/usr/share/fonts/"}
}