Unicode Support

library(lofifonts)

Unicode support

Each font supports a different number of glyphs. The vector fonts include just the ASCII character sets.

The font with the best unicode coverage is the bitmap font unifont which supports over 50 thousand glyphs.

Font overview

Type Name Sizes Unicode? # glyphs
Bitmap Spleen 5x8, 6x12, 8x16, 12x24, 16x32 Some 450-1000
Bitmap Tamzen 5x9, 6x12, 7x13, 8x15, 8x16, 10x20 bold/regular Some 180
Bitmap Unifont 16x16 Yes. Plane 0, 1 113446
Bitmap Unscii 8x8, 8x16 Some 3240
Vector gridfont Lower case ASCII only 68
Vector gridfont_smooth Lower case ASCII only 68
Vector arcade Upper case ASCII only 66

Rendering with unifont

txt <- "二項分布\xF0\x9F\x8E\xB2の英語表記は\n「Binomial distribution」である。"

bitmap_text_raster(txt, "unifont") |>
  plot()

Default character

When a particular unicode glyph is not available, some fonts define a default character which should be used instead.

If a default character is not defined for a font then unknown characters will use ?

Codepoints supported by each font

Here is an example of looking for the thumbs-down and thumbs-up glyphs.

codepoints <- c(0x1f44d, 0x1f44e)

unifont <- get_lofi_font('unifont')
unifont
#> [lofi bitmap font] 16 x 16. 113446 codepoints.  Width min/median/max = 8, 16, 16
# Unifont has both of these
codepoints %in% unifont$glyph_info$codepoint
#> [1] TRUE TRUE
bitmap_text_raster(intToUtf8(codepoints), 'unifont') |> plot()

spleen <- get_lofi_font('spleen-5x8')
spleen
#> [lofi bitmap font] 5 x 8. 472 codepoints.
# This spleen font has neither
codepoints %in% spleen$glyph_info$codepoint
#> [1] FALSE FALSE
bitmap_text_raster(intToUtf8(codepoints), 'spleen-5x8') |> plot()