| Title: | Download and Register Fonts from GDPR-Compliant Providers For Use In R graphics |
|---|---|
| Description: | Download and register fonts from GDPR-compliant providers for use in R graphics. Currently supports Bunny Fonts (<https://fonts.bunny.net/>/). Architecture allows for easy additions of font providers. |
| Authors: | Guillaume Noblet [aut, cre, cph] |
| Maintainer: | Guillaume Noblet <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.2.0 |
| Built: | 2026-05-13 09:05:07 UTC |
| Source: | https://codeberg.org/gnoblet/AddFonts |
Ensure a font is available locally: try the cache first, otherwise download/convert and register the font so it can be used by plotting devices. Returns (invisibly) the list of local file paths.
add_font( name, provider = "bunny", family = NULL, regular.wt = 400, bold.wt = 700, subset = "latin" )add_font( name, provider = "bunny", family = NULL, regular.wt = 400, bold.wt = 700, subset = "latin" )
name |
( |
provider |
( |
family |
( |
regular.wt |
( |
bold.wt |
( |
subset |
( |
(list) Invisibly returns a list with paths for regular, italic, bold and bolditalic variants, or throws an error on failure.
Read from list
as_CacheEntryList(l)as_CacheEntryList(l)
l |
( |
(CacheEntryList) The CacheEntryList object created from the list.
FontProvider from a named listConstruct a FontProvider from a named list
as_FontProvider(x)as_FontProvider(x)
x |
( |
(FontProvider) The corresponding FontProvider object.
As list
as_list(x)as_list(x)
x |
( |
(list) The list representation of the CacheEntryList.
Remove entries from the cache, optionally unlinking referenced files.
cache_clean(cache_dir = NULL, families = NULL, reset = FALSE, ...)cache_clean(cache_dir = NULL, families = NULL, reset = FALSE, ...)
cache_dir |
( |
families |
( |
reset |
( |
... |
( |
(character | NULL) Invisibly returns character vector of removed family names when deleting specific entries, or NULL when nothing changed. Remove files by default.
Other cache:
cache_get(),
cache_get_weights(),
cache_read(),
cache_remove(),
cache_write()
Get certain families from CacheEntryList
cache_get(x, families = NULL, quiet = TRUE)cache_get(x, families = NULL, quiet = TRUE)
x |
( |
families |
( |
quiet |
( |
(list) A list of CacheEntry objects matching the specified families. If no families
Other cache:
cache_clean(),
cache_get_weights(),
cache_read(),
cache_remove(),
cache_write()
Check which weights are available in a cache entry
cache_get_weights(entry, weights)cache_get_weights(entry, weights)
entry |
( |
weights |
( |
(lgl) Logical vector indicating which weights are cached).
Other cache:
cache_clean(),
cache_get(),
cache_read(),
cache_remove(),
cache_write()
Read cache entry from disk
cache_read(cache_dir)cache_read(cache_dir)
cache_dir |
( |
(CacheEntryList) The cache index as a
Other cache:
cache_clean(),
cache_get(),
cache_get_weights(),
cache_remove(),
cache_write()
Delete entry from cache
cache_remove(x, families = NULL, remove_files = TRUE, cache_dir = NULL)cache_remove(x, families = NULL, remove_files = TRUE, cache_dir = NULL)
x |
( |
families |
( |
remove_files |
( |
cache_dir |
( |
(CacheEntryList) The modified CacheEntryList with the specified entries removed.
Other cache:
cache_clean(),
cache_get(),
cache_get_weights(),
cache_read(),
cache_write()
Set cache entries
cache_set(x, family, meta)cache_set(x, family, meta)
x |
( |
family |
( |
meta |
( |
(CacheEntryList) The modified CacheEntryList with the updated entry.
Compose canonical filename for a cached TTF
cache_ttf_filename(source, font_id, subset, weight, style)cache_ttf_filename(source, font_id, subset, weight, style)
source |
( |
font_id |
( |
subset |
( |
weight |
( |
style |
( |
(character(1)) Filename (not including the cache directory) for the cached TTF.
Compute canonical cache path for a TTF file
cache_ttf_path(source, font_id, subset, weight, style, cache_dir = NULL)cache_ttf_path(source, font_id, subset, weight, style, cache_dir = NULL)
source |
( |
font_id |
( |
subset |
( |
weight |
( |
style |
( |
cache_dir |
( |
(character(1)) Path to the cached .ttf file.
Compute paths used for caching provider artifacts and any conversion intermediate files.
cache_variant_paths(provider, family, weight, style, subset, cache_dir = NULL)cache_variant_paths(provider, family, weight, style, subset, cache_dir = NULL)
provider |
( |
family |
( |
weight |
( |
style |
( |
subset |
( |
cache_dir |
( |
(list) A list with elements to_convert (path or NULL) and ttf (path).
Write CacheEntryList to disk as JSON
cache_write(x, cache_dir = NULL, quiet = TRUE)cache_write(x, cache_dir = NULL, quiet = TRUE)
x |
( |
cache_dir |
( |
quiet |
( |
(NULL) Invisibly returns NULL.
Other cache:
cache_clean(),
cache_get(),
cache_get_weights(),
cache_read(),
cache_remove()
S7-backed cache entry (CacheEntry)
CacheEntry(family = character(0), meta = CacheMeta())CacheEntry(family = character(0), meta = CacheMeta())
family |
( |
meta |
( |
(S7_object) A validated S7 CacheEntry object.
S7 list of cache entries (CacheEntryList)
CacheEntryList(entries = list())CacheEntryList(entries = list())
entries |
( |
(S7_object) A validated S7 CacheEntryList object.
S7-backed cache metadata (CacheMeta)
CacheMeta(family_id = character(0), source = character(0), files = list())CacheMeta(family_id = character(0), source = character(0), files = list())
family_id |
( |
source |
( |
files |
( |
The added property is a getter-only field that returns the current timestamp as a character string when accessed. It cannot be set during construction.
Weights are not explicitly stored - they are derived from the names of the files list. Registration functions are responsible for selecting appropriate weights for regular/bold variants.
(S7_object) A validated S7 CacheMeta object.
woff2_to_ttf).Resolve a conversion name to the converter function used by the
package (currently only woff2_to_ttf).
conv_fun(conversion)conv_fun(conversion)
conversion |
( |
(function) The conversion function if known; otherwise the helper aborts.
Attempt to delete a set of files (character vector or list of paths).
delete_files(entries, quiet = c("full", "success", "fail", "none"))delete_files(entries, quiet = c("full", "success", "fail", "none"))
entries |
( |
quiet |
(full" | "success" | "fail" | "none) If "full", capture all output and suppress console messages; if "success", only show success messages; if "fail", only show error messages; if "none", show all messages (default: "none"). |
(list) A list with the following elements:
deleted: character() — paths successfully deleted
failed: character() — paths that existed but could not be deleted
not_found: character() — paths that were not found on disk
Downloads font files for requested weights, creates a cache entry, and writes to cache. Does NOT register the font - caller should use register_from_cache() for that.
download_and_cache( provider, name, font_id, family_name, regular.wt = 400, bold.wt = 700, subset = "latin", cache_dir = NULL )download_and_cache( provider, name, font_id, family_name, regular.wt = 400, bold.wt = 700, subset = "latin", cache_dir = NULL )
provider |
( |
name |
( |
font_id |
( |
family_name |
( |
regular.wt |
( |
bold.wt |
( |
subset |
( |
cache_dir |
( |
(CacheEntry | NULL) Cache entry with downloaded fonts, or NULL on failure.
Download and (if needed) convert a provider artifact to a local TTF file for a given family/weight/style and return the local path.
download_variant_generic( provider, family, weight, style, subset = "latin", cache_dir = NULL, quiet = FALSE )download_variant_generic( provider, family, weight, style, subset = "latin", cache_dir = NULL, quiet = FALSE )
provider |
( |
family |
( |
weight |
( |
style |
( |
subset |
( |
cache_dir |
( |
quiet |
( |
(character | NULL) Path to the local .ttf file on success, or NULL on failure.
Downloads normal and italic variants for each weight and returns a named list with weight-based keys.
download_weights(provider, name, weights, subset, cache_dir, quiet = TRUE)download_weights(provider, name, weights, subset, cache_dir, quiet = TRUE)
provider |
( |
name |
( |
weights |
( |
subset |
( |
cache_dir |
( |
quiet |
( |
(list) Named list where names are weight identifiers (e.g., "400", "700italic")
and values are file paths.
Font provider specification (FontProvider)
FontProvider( source = character(0), url_template = character(0), conversion = NULL, conversion_ext = NULL, aliases = list() )FontProvider( source = character(0), url_template = character(0), conversion = NULL, conversion_ext = NULL, aliases = list() )
source |
( |
url_template |
( |
conversion |
( |
conversion_ext |
( |
aliases |
( |
(FontProviders) S7 class representing a font provider specification.
Determine a platform-appropriate cache directory for AddFonts and ensure it exists, creating it when necessary.
get_cache_dir()get_cache_dir()
(character(1)) Absolute path to the cache directory.
Load and return a FontProvider object for the specified provider. The providers data is stored in the package's internal sysdata.rda.
get_provider_details(provider)get_provider_details(provider)
provider |
( |
(FontProvider) A validated FontProvider object.
Ensure the requested font is installed via add_font() and draw a brief
sample using showtext for proper font rendering.
preview_font( name, provider = "bunny", family = NULL, sample = "The quick brown fox jumps over the lazy dog", size = 28, subset = "latin", regular.wt = 400, bold.wt = 700 )preview_font( name, provider = "bunny", family = NULL, sample = "The quick brown fox jumps over the lazy dog", size = 28, subset = "latin", regular.wt = 400, bold.wt = 700 )
name |
( |
provider |
( |
family |
( |
sample |
( |
size |
( |
subset |
( |
regular.wt |
( |
bold.wt |
( |
(list) Invisibly returns the list of paths produced by add_font().
files list or NULL when
registration cannot proceed.This is the ONLY function that calls sysfonts::font_add(). It does not print success messages - callers should handle user feedback.
register_from_cache(entry, regular.wt = 400, bold.wt = 700)register_from_cache(entry, regular.wt = 400, bold.wt = 700)
entry |
( |
regular.wt |
( |
bold.wt |
( |
(list | NULL) Prepared files list (with regular, italic, bold, bolditalic) or NULL.
sysfonts. Returns the prepared files list
on success, or NULL if a regular font could not be obtained.This function downloads fonts, creates a cache entry, and then calls register_from_cache() to perform the actual registration with sysfonts.
register_from_download( provider, name, font_id, family_name, regular.wt = 400, bold.wt = 700, subset = "latin", cache_dir = NULL )register_from_download( provider, name, font_id, family_name, regular.wt = 400, bold.wt = 700, subset = "latin", cache_dir = NULL )
provider |
( |
name |
( |
font_id |
( |
family_name |
( |
regular.wt |
( |
bold.wt |
( |
subset |
( |
cache_dir |
( |
(list | NULL) List of local file paths for variants, or NULL on failure.
Replace disallowed characters with - and convert to lower-case so
the resulting id is safe to use in filenames.
safe_id(name)safe_id(name)
name |
( |
(character(1)) Sanitised identifier.
Downloads missing font weights and updates the cache entry. Does NOT register the font - use register_from_cache() after this.
update_download_and_cache( entry, provider, name, family_name, missing_weights, subset = "latin", cache_dir = NULL, cel = NULL )update_download_and_cache( entry, provider, name, family_name, missing_weights, subset = "latin", cache_dir = NULL, cel = NULL )
entry |
( |
provider |
( |
name |
( |
family_name |
( |
missing_weights |
( |
subset |
( |
cache_dir |
( |
cel |
( |
(CacheEntry | NULL) Updated cache entry with new weights (NOT registered), or NULL on failure.
Internal helper. Uses the system woff2_decompress tool to convert a
.woff2 file into a .ttf file. Documented with roxytypes annotations
for clarity.
woff2_to_ttf(font_file, overwrite = FALSE, remove_old = TRUE, quiet = "fail")woff2_to_ttf(font_file, overwrite = FALSE, remove_old = TRUE, quiet = "fail")
font_file |
( |
overwrite |
( |
remove_old |
( |
quiet |
(full" | "success" | "fail" | "none) If "full", capture all output and suppress console messages; if "success", only show success messages; if "fail", only show error messages; if "none", show all messages (default: "none"). |
(character(1)) Invisibly returns the path to the .ttf file on success.