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 Unicode? # glyphs
Bitmap Spleen Some 450-1000
Bitmap Unifont Lots! 57086
Bitmap Unscii 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(interpolate = FALSE)

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 ?

Lists of supported codepoints

The unicode glyphs supported by each font are listed in the font_info data structure.

# Cozette font - number of codepoints and a list of the first 200
font_info$bitmap$`spleen-12x24`$codepoints |> 
  length()
#> [1] 0
font_info$bitmap$`spleen-12x24`$codepoints |> 
  head(60)
#> integer(0)
font_info$bitmap$`spleen-12x24`$codepoints |> 
  head(60) |>
  intToUtf8()
#> [1] ""
# Arcade font - includes 66 codepoints
font_info$vector$arcade$codepoints
#>  [1]  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83
#> [20]  84  85  86  87  88  89  90  48  49  50  51  52  53  54  55  56  57  46  44
#> [39]  45  32  61  33  63  58  59  35  39  34  91  93  40  41 123 125  36  43  47
#> [58]  42  37  94 124  95  60  62  38  64
intToUtf8(font_info$vector$arcade$codepoints)
#> [1] "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,- =!?:;#'\"[](){}$+/*%^|_<>&@"