{naratext}
renders text to nativeRaster images in memory.
This relies of glyph rendering features in the {grid}
package.
nr_text()
to render text to in-memory nativeRaster images
- Reconcile the different font handling mechanisms between
textshaping
andgrDevices::glyphFont()
- Tightly crop the returned nativeRaster
- Return baseline offset from bottom of raster so that other compositors
(e.g.
{nara}
) now how to place text correctly - Move to textshaping’s C interface?
Installation from GitHub
Also requires installation of:
- CRAN packages:
{textshaping}
to calculate positions of rendered glyph{ragg}
as a graphics device that allows direct capture of the output to an image in memory (and supports glyph rendering)- ‘{bittermelon}’ for handling bitmap fonts
- GitHub packages
{nara}
for nativeRaster utilities
install.packages('remotes')
remotes::install_github('coolbutuseless/nara')
install.packages(c('textshaping', 'ragg'))
remotes::install_github('coolbutuseless/naratext')
library(grid)
library(nara)
library(naratext)
strings <- c('Ping', ' #RStats')
font_files <- c(
system.file("fonts", "Montserrat", "static", "Montserrat-BoldItalic.ttf", package="grDevices"),
system.file("fonts", "Montserrat", "static", "Montserrat-Medium.ttf" , package="grDevices")
)
color <- c('red', 'blue')
txt <- nr_text(strings, font_files = font_files, color = color, scale = 10, background = 'lightblue')
dim(txt)
#> [1] 147 801
class(txt)
#> [1] "nativeRaster"
grid.raster(txt, interpolate = FALSE)
library(grid)
library(nara)
library(naratext)
font_file <- system.file("fonts/spleen/spleen-8x16.hex.gz", package = "bittermelon")
font <- bittermelon::read_hex(font_file)
txt <- nr_text_bitmap("Ping #RStats", font = font, fill = 'lightpink')
dim(txt)
#> [1] 16 96
grid::grid.newpage(); grid::grid.raster(txt, interpolate = FALSE)
font <- bittermelon::read_monobit("~/projectsdata/spleen/spleen-32x64.bdf", quietly = TRUE)
txt <- nr_text_bitmap("Ping #RStats", font = font, fill = 'lightgreen')
dim(txt)
#> [1] 64 384
grid::grid.newpage(); grid::grid.raster(txt, interpolate = FALSE)