fontdirs_unix.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // +build dragonfly freebsd linux nacl netbsd openbsd solaris
  2. // Copyright 2016 Florian Pigorsch. All rights reserved.
  3. //
  4. // Use of this source code is governed by a MIT-style
  5. // license that can be found in the LICENSE file.
  6. package findfont
  7. import (
  8. "os"
  9. "path/filepath"
  10. )
  11. func getFontDirectories() (paths []string) {
  12. directories := getUserFontDirs()
  13. directories = append(directories, getSystemFontDirs()...)
  14. return directories
  15. }
  16. func getUserFontDirs() (paths []string) {
  17. if dataPath := os.Getenv("XDG_DATA_HOME"); dataPath != "" {
  18. return []string{expandUser("~/.fonts/"), filepath.Join(expandUser(dataPath), "fonts")}
  19. }
  20. return []string{expandUser("~/.fonts/"), expandUser("~/.local/share/fonts/")}
  21. }
  22. func getSystemFontDirs() (paths []string) {
  23. if dataPaths := os.Getenv("XDG_DATA_DIRS"); dataPaths != "" {
  24. for _, dataPath := range filepath.SplitList(dataPaths) {
  25. paths = append(paths, filepath.Join(expandUser(dataPath), "fonts"))
  26. }
  27. return paths
  28. }
  29. return []string{"/usr/local/share/fonts/", "/usr/share/fonts/"}
  30. }