Please note this README is best viewed elsewhere
than github.com
. github.com
’s default
line-height
setting causes distracting extraneous
horizontal lines to appear when “printing” bitmaps and
github.com
does
not allow using CSS to set a more reasonable
line-height
value.
{bittermelon}
provides functions for creating and
modifying bitmaps with special emphasis on bitmap fonts and their
glyphs. It provides native read/write support for the ‘hex’ and ‘yaff’
bitmap font formats and if ‘Python’ is installed can also read/write
several more bitmap font formats using an embedded version of monobit. It features
over
a dozen functions that can modify individual bitmaps or every bitmap
within a “bitmap list” or “bitmap font”. {bittermelon}
can
also pretty print bitmaps to the terminal and has a basic plot
method.
::install_github("trevorld/bittermelon") remotes
The functions read_monobit()
and
write_monobit()
that use the embedded version of monobit require that
Python is available on the system. A couple of the bitmap font output
formats supported by write_monobit()
also require that the
“Pillow” or “reportlab” Python packages are installed (installable via
pip3
).
library("bittermelon") # remotes::install_github("trevorld/bittermelon")
Attaching package: 'bittermelon'
The following object is masked from 'package:base':
which
<- system.file("fonts/spleen/spleen-8x16.hex.gz", package = "bittermelon")
font_file <- read_hex(font_file)
font <- as_bm_list("RSTATS", font = font)
bml # With vertical compression
<- bml |> bm_call(cbind) |> bm_compress("vertical")
bm print(bm)
██▀▀▀█▄ ▄█▀▀▀▀▀ ▀▀▀██▀▀▀▄█▀▀▀█▄ ▀▀▀██▀▀▀▄█▀▀▀▀▀
██ ██ ██ ██ ██ ██ ██ ██
██▀▀▀█▄ ▀▀▀▀█▄ ██ ██▀▀▀██ ██ ▀▀▀▀█▄
██ ██ ██ ██ ██ ██ ██ ██
██ ██ ▄▄▄▄▄█▀ ██ ██ ██ ██ ▄▄▄▄▄█▀
# Upside down with ASCII characters
<- bml |>
bm bm_flip("both") |>
bm_call(cbind, direction = "RTL")
print(bm, px = px_ascii)
------------------------------------------------
------------------------------------------------
------------------------------------------------
------------------------------------------------
--@@@@@@---@@----@@---@@---@@-----@@@@@@-@@---@@
-@@--------@@----@@---@@---@@----@@------@@---@@
-@@--------@@----@@---@@---@@----@@------@@---@@
-@@--------@@----@@---@@---@@----@@------@@---@@
-@@--------@@----@@---@@---@@----@@------@@---@@
--@@@@@----@@----@@@@@@@---@@-----@@@@@---@@@@@@
------@@---@@----@@---@@---@@---------@@-@@---@@
------@@---@@----@@---@@---@@---------@@-@@---@@
------@@---@@----@@---@@---@@---------@@-@@---@@
-@@@@@@-@@@@@@@@--@@@@@-@@@@@@@@-@@@@@@---@@@@@@
------------------------------------------------
------------------------------------------------
# With a shadow effect and borders
<- bml |>
bm bm_pad(sides = 2L) |>
bm_shadow() |>
bm_extend(sides = c(2L, 1L), value = 3L) |>
bm_call(cbind) |>
bm_pad(sides = 2L, value = 3L)
print(bm)
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓░░░░░░░░░░░░▓▓░░░░░░░░░░░░▓▓░░░░░░░░░░░░░▓▓░░░░░░░░░░░░▓▓░░░░░░░░░░░░░▓▓░░░░░░░░░░░░▓▓
▓▓░░░░░░░░░░░░▓▓░░░░░░░░░░░░▓▓░░░░░░░░░░░░░▓▓░░░░░░░░░░░░▓▓░░░░░░░░░░░░░▓▓░░░░░░░░░░░░▓▓
▓▓░░██████░░░░▓▓░░░██████░░░▓▓░░████████░░░▓▓░░░█████░░░░▓▓░░████████░░░▓▓░░░██████░░░▓▓
▓▓░░██▒▒▒██░░░▓▓░░██▒▒▒▒▒▒░░▓▓░░░▒▒██▒▒▒▒░░▓▓░░██▒▒▒██░░░▓▓░░░▒▒██▒▒▒▒░░▓▓░░██▒▒▒▒▒▒░░▓▓
▓▓░░██▒░░██▒░░▓▓░░██▒░░░░░░░▓▓░░░░░██▒░░░░░▓▓░░██▒░░██▒░░▓▓░░░░░██▒░░░░░▓▓░░██▒░░░░░░░▓▓
▓▓░░██▒░░██▒░░▓▓░░██▒░░░░░░░▓▓░░░░░██▒░░░░░▓▓░░██▒░░██▒░░▓▓░░░░░██▒░░░░░▓▓░░██▒░░░░░░░▓▓
▓▓░░██████▒▒░░▓▓░░░█████░░░░▓▓░░░░░██▒░░░░░▓▓░░███████▒░░▓▓░░░░░██▒░░░░░▓▓░░░█████░░░░▓▓
▓▓░░██▒▒▒██░░░▓▓░░░░▒▒▒██░░░▓▓░░░░░██▒░░░░░▓▓░░██▒▒▒██▒░░▓▓░░░░░██▒░░░░░▓▓░░░░▒▒▒██░░░▓▓
▓▓░░██▒░░██▒░░▓▓░░░░░░░██▒░░▓▓░░░░░██▒░░░░░▓▓░░██▒░░██▒░░▓▓░░░░░██▒░░░░░▓▓░░░░░░░██▒░░▓▓
▓▓░░██▒░░██▒░░▓▓░░░░░░░██▒░░▓▓░░░░░██▒░░░░░▓▓░░██▒░░██▒░░▓▓░░░░░██▒░░░░░▓▓░░░░░░░██▒░░▓▓
▓▓░░██▒░░██▒░░▓▓░░░░░░░██▒░░▓▓░░░░░██▒░░░░░▓▓░░██▒░░██▒░░▓▓░░░░░██▒░░░░░▓▓░░░░░░░██▒░░▓▓
▓▓░░██▒░░██▒░░▓▓░░██████▒▒░░▓▓░░░░░██▒░░░░░▓▓░░██▒░░██▒░░▓▓░░░░░██▒░░░░░▓▓░░██████▒▒░░▓▓
▓▓░░░▒▒░░░▒▒░░▓▓░░░▒▒▒▒▒▒░░░▓▓░░░░░░▒▒░░░░░▓▓░░░▒▒░░░▒▒░░▓▓░░░░░░▒▒░░░░░▓▓░░░▒▒▒▒▒▒░░░▓▓
▓▓░░░░░░░░░░░░▓▓░░░░░░░░░░░░▓▓░░░░░░░░░░░░░▓▓░░░░░░░░░░░░▓▓░░░░░░░░░░░░░▓▓░░░░░░░░░░░░▓▓
▓▓░░░░░░░░░░░░▓▓░░░░░░░░░░░░▓▓░░░░░░░░░░░░░▓▓░░░░░░░░░░░░▓▓░░░░░░░░░░░░░▓▓░░░░░░░░░░░░▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
# Can also print colored terminal output via suggested package {crayon}
if (crayon::has_color())
print(bm, px = " ", bg = c("white", "black", "grey", "red"))
plot(bm, col = c("white", "darkblue", "lightblue", "black"))
{bittermelon}
has a builtin versions of the 8x16 Spleen font as well as 4x6
and 6x13 Fixed
fonts.
<- read_hex(system.file("fonts/spleen/spleen-8x16.hex.gz",
spleen_8x16 package = "bittermelon"))
<- read_yaff(system.file("fonts/fixed/4x6.yaff.gz",
fixed_4x6 package = "bittermelon"))
<- read_yaff(system.file("fonts/fixed/5x8.yaff.gz",
fixed_5x8 package = "bittermelon"))
<- read_yaff(system.file("fonts/fixed/6x13.yaff.gz",
fixed_6x13 package = "bittermelon"))
as_bm_bitmap("RSTATS", font = spleen_8x16) |> bm_compress("v")
██▀▀▀█▄ ▄█▀▀▀▀▀ ▀▀▀██▀▀▀▄█▀▀▀█▄ ▀▀▀██▀▀▀▄█▀▀▀▀▀
██ ██ ██ ██ ██ ██ ██ ██
██▀▀▀█▄ ▀▀▀▀█▄ ██ ██▀▀▀██ ██ ▀▀▀▀█▄
██ ██ ██ ██ ██ ██ ██ ██
██ ██ ▄▄▄▄▄█▀ ██ ██ ██ ██ ▄▄▄▄▄█▀
as_bm_bitmap("RSTATS", font = fixed_4x6) |> bm_compress("v")
█▀▄ ▄▀▀ ▀█▀ ▄▀▄ ▀█▀ ▄▀▀
█▀▄ ▀▄ █ █▀█ █ ▀▄
▀ ▀ ▀▀ ▀ ▀ ▀ ▀ ▀▀
as_bm_bitmap("RSTATS", font = fixed_5x8) |> bm_compress("v")
▄▄▄ ▄▄ ▄▄▄ ▄▄ ▄▄▄ ▄▄
█ █ ▀▄ ▀ █ █ █ █ ▀▄ ▀
█▀▀▄ ▄ ▀▄ █ █▀▀█ █ ▄ ▀▄
▀ ▀ ▀▀ ▀ ▀ ▀ ▀ ▀▀
as_bm_bitmap("RSTATS", font = fixed_6x13) |> bm_compress("v")
█▀▀▀▄ ▄▀▀▀▄ ▀▀█▀▀ ▄▀▄ ▀▀█▀▀ ▄▀▀▀▄
█ █ █ █ █ █ █ █
█▀█▀ ▀▀▀▄ █ █▄▄▄█ █ ▀▀▀▄
█ ▀▄ ▄ █ █ █ █ █ ▄ █
▀ ▀ ▀▀▀ ▀ ▀ ▀ ▀ ▀▀▀
The {hexfont}
package includes a helper function unifont()
which loads
several GNU Unifont hex fonts as a single {bittermelon}
bm_font()
object. GNU Unifont is a
monoscale bitmap font (8x16 and 16x16 glyphs) that pretty much covers
all of the official Unicode glyphs plus several of the artificial
scripts in the (Under-)ConScript Unicode
Registry.
library("hexfont") # remotes::install_github("trevorld/hexfont")
system.time(font <- unifont()) # Unifont is a **big** font
user system elapsed
60.958 0.072 61.036
length(font) |> prettyNum(big.mark = ",") # number of glyphs
[1] "77,418"
object.size(font) |> format(units = "MB") # memory used
[1] "116 Mb"
# Mandarin Chinese
as_bm_bitmap("R很棒!", font = font) |> bm_compress("v")
█ ▄▄▄▄▄▄▄ █ █
▄▀ █ █ █ ▀▀▀▀█▀▀▀▀
██▀▀▀▀▀▀▀▀▄▄ ▀ █ █▀▀▀▀▀█ ▀▀▀█▀▀ ▀▀█▀▀▀▀ ██
██ ██ ▄█ █▄▄▄▄▄█ ██▄ ▀▀█▀▀▀█▀▀ ██
██▀▀▀▀██▀▀ ▄▀ █ █ █ ▄▀ █ █ ▀▄▀ █ ▀▄ ██
██ ██ █ █ █▀ ▀ █ ▀▀█▀▀ ▀▀
██ ██ █ █ ▄ ▀▄ █ ▀▀▀▀█▀▀▀▀ ██
█ █▀ ▀▀ █ █
# Emoji
as_bm_bitmap("🐭🐲🐵", font = font) |> bm_compress("v")
▄▄ ▄▄ ▄▄▄ ▄▄
▄▀ ▀▄▄▄▄▄▀ ▀▄ ▄█▀ ▄█▀██▀█▄
█ ▀ ▀ █ ▄████ ▄▀█ ▄▄ ▄▄ █▀▄
▄█ ▀ ▀ █▄ ▄▄██▄█████ ▀▄█ ▀▀ ▀▀ █▄▀
▄█▀ ▄ ▀█▄ ▄█▄███████████ ▄▀ ▀▄
▀▄ ▀▀▀ ▄▀ ▀▀▀▀▀███▀▀█████ █ ▀▄▄▄▄▀ █
▀▀▄▄▄▀▀ ▄███ ████▀ ▀▀▄▄▄▄▀▀
▀▀▀ ▀▀▀
I wrote {bittermelon}
in order to help create Game Bit, a
fixed-width bitmap
font specialized for making board game diagrams. The duospaced
version is called Game Bit Duo while the square monospaced
version is called Game Bit Mono. Check out the Game Bit Github
repo to see an extended example of using {bittermelon}
to make a custom font (albeit with several glyphs adopted/adapted from
GNU
Unifont).
{bittermelon}
will likely support including a specialized
{ggplot2}
geom.{bittermelon}
.Fixed aka “Unicode fonts and tools for X11”
Embedded in {hexfont}
package:
Embedded in {bdftools}
package: