The function unifont() loads in several GNU Unifont hex files as a
single bittermelon::bm_font() object.
Usage
unifont(
upper = TRUE,
jp = FALSE,
csur = TRUE,
sample = FALSE,
ucp = NULL,
cache = getOption("unifont.cache", NULL)
)Arguments
- upper
Include glyphs above the Unicode Basic Multilingual plane.
- jp
Use Japanese version of Chinese characters.
- csur
Include (Under-)Conscript Unicode Registry glyphs.
- sample
Add circle to "Combining" characters.
- ucp
Character vector of Unicode Code Points: glyphs not in this vector won't be read in. If
NULL(default) read every glyph in the font.- cache
If
TRUEread a cached version of this font fromtools::R_user_dir("hexfont", "cache")if it exists and if it does not exist than create a cached version of this font. IfFALSEdon't read or write a cached version of this font (even if it exists). IfNULLread a cached version of this font if it exists but if it does not exist then don't create it. This argument is ignored ifucpis notNULL.
Value
A bittermelon::bm_font() object.
If cache is TRUE then as a side effect may create an .rds file
in tools::R_user_dir("hexfont", "cache").
Examples
# Much faster to load only the subset of GNU Unifont one needs
# Mandarin Chinese
if (require("bittermelon")) {
s <- "\uff32\u5f88\u68d2\uff01"
font <- unifont(ucp = str2ucp(s))
bm <- as_bm_bitmap(s, font = font)
print(bm, px = px_ascii)
}
#> Loading required package: bittermelon
#> --------------------@--------------@------@---------------------
#> --------------------@-@@@@@@@------@------@---------------------
#> -------------------@--@-----@------@--@@@@@@@@@-------@---------
#> ---@@@@@@@--------@---@-----@------@------@----------@@@--------
#> ----@-----@------@--@-@@@@@@@---@@@@@@-@@@@@@@-------@@@--------
#> ----@------@--------@-@-----@------@-----@-----------@@@--------
#> ----@------@-------@--@-----@-----@@--@@@@@@@@@------@@@--------
#> ----@-----@-------@@--@@@@@@@-----@@@---@---@---------@---------
#> ----@@@@@@-------@-@--@--@---@---@-@-@-@--@--@--------@---------
#> ----@---@-------@--@--@--@--@----@-@--@---@---@-------@---------
#> ----@----@---------@--@---@@----@--@----@@@@@-------------------
#> ----@-----@--------@--@---@--------@------@---------------------
#> ----@------@-------@--@----@-------@--@@@@@@@@@-------@---------
#> ---@@@----@@@------@--@-@---@------@------@-----------@---------
#> -------------------@--@@-----@@----@------@---------------------
#> -------------------@--@------------@------@---------------------
# Emoji
if (require("bittermelon")) {
s <- "\U0001f42d\U0001f432\U0001f435"
font <- unifont(ucp = str2ucp(s))
bm <- as_bm_bitmap(s, font = font)
print(bm, px = px_ascii)
}
#> ------------------------------------------------
#> --@@-------@@-----------@@@------------@@-------
#> -@--@-----@--@---------@@------------@@@@@@-----
#> @----@@@@@----@-------@@------------@@-@@-@@----
#> @----@---@----@-------@@@@--------@@--------@@--
#> @-------------@------@@@@@-------@-@-@@--@@-@-@-
#> -@---@---@---@------@@-@@@@@-----@-@-@@--@@-@-@-
#> @@-----------@@---@@@@@@@@@@------@@--------@@--
#> -@@---------@@---@-@@@@@@@@@@@------@------@----
#> @@-----@-----@@-@@@@@@@@@@@@@@-----@--------@---
#> --@---@@@---@---@@@@@@@@@@@@@@@----@-@----@-@---
#> ---@-------@---------@@@--@@@@@----@--@@@@--@---
#> ----@@---@@---------@@@---@@@@@-----@@----@@----
#> ------@@@----------@@@@---@@@@--------@@@@------
#> ------------------@@@-----@@@-------------------
#> ------------------------------------------------
# Will take more than 5s on CRAN machines
# Compiling the entire font from the hex files takes a long time
system.time(font <- unifont(cache = FALSE))
#> user system elapsed
#> 67.354 0.105 67.487
prettyNum(length(font), big.mark = ",") # number of glyphs
#> [1] "125,472"
# It is usually much faster to use a cached version of the font
if (file.exists(hexfont:::unifont_cache_filename())) {
system.time({font_from_cache <- unifont(cache = TRUE)})
}
#> user system elapsed
#> 0.338 0.001 0.339