-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable adding a custom directory to the system font search path(s)? #68
Comments
There is no way to add a path that would be treated equally as the fonts installed in the system. I can see a good reason for some path scanning functionality however so let me think about the right API |
Would it be possible to add a function that helps installing the font in the correct user directory instead ? It seems that {extrafont} will hardly be maintained now (https://github.com/wch/Rttf2pt1) Maybe we can retrieve this function that list all possible user font directories. install_font <- function(from, to) {
# writeable directory
if (is.empty(to)) {
to <- ttf_find_default_path()[file.access(ttf_find_default_path(), mode = 2)[[1]] == 0)][1]
}
# Copy from internal package and external directory
file.copy(
from,
to
)
}
install_font(system.file("my_fonts", package = "a.package.with.fonts")) Retrieved from: https://github.com/wch/extrafont/blob/054a41fcba237cbb693144a0fc7b23a9e30f0c2b/R/truetype.r#L125 # Returns vector of default truetype paths, depending on platform.
ttf_find_default_path <- function() {
if (grepl("^darwin", R.version$os)) {
paths <-
c("/Library/Fonts/", # System fonts
"/System/Library/Fonts", # More system fonts
"/System/Library/Fonts/Supplemental", # More system fonts
"~/Library/Fonts/") # User fonts
return(paths[file.exists(paths)])
} else if (grepl("^linux-gnu", R.version$os)) {
# Possible font paths, depending on the system
paths <-
c("/usr/share/fonts/", # Ubuntu/Debian/Arch/Gentoo
"/usr/X11R6/lib/X11/fonts/TrueType/", # RH 6
"~/.local/share/fonts/", # Added with Gnome font viewer
"~/.fonts/") # User fonts
return(paths[file.exists(paths)])
} else if (grepl("^freebsd", R.version$os)) {
# Possible font paths, depending on installed ports
paths <-
c("/usr/local/share/fonts/truetype/",
"/usr/local/lib/X11/fonts/",
"~/.fonts/") # User fonts
return(paths[file.exists(paths)])
} else if (grepl("^mingw", R.version$os)) {
paths <-
c(file.path(Sys.getenv("SystemRoot"), "Fonts"),
file.path(Sys.getenv("LOCALAPPDATA"), "Microsoft", "Windows", "Fonts")
)
return(paths[file.exists(paths)])
} else {
stop("Unknown platform. Don't know where to look for truetype fonts. Sorry!")
}
} In which, I would add if (.Platform == "windows") {
user_font <- normalizePath(file.path(dirname(Sys.getenv("HOME")), "AppData/Local/Microsoft/Windows/Fonts"))
} |
This is now possible using |
From what I gather, with something like this — https://github.com/hrbrmstr/hrbragg/tree/master/inst/fonts/inter —
in a package, to get the equivalent of this:
in an R session registry, I'd have to deal with the individual registrations for the various weights. Is there any way with the new underlying tooling to specify another search path or have a registration function that just takes a path and registers all the fonts in that directory?
The text was updated successfully, but these errors were encountered: