as_bm_bitmap: Coerce to bitmap glyph objects

View source: R/as_bm_bitmap.R

as_bm_bitmapR Documentation

Coerce to bitmap glyph objects

Description

as_bm_bitmap() turns an existing object into a bm_bitmap() object.

Usage

as_bm_bitmap(x, ...)

## S3 method for class 'matrix'
as_bm_bitmap(x, ...)

## Default S3 method:
as_bm_bitmap(x, ...)

## S3 method for class 'character'
as_bm_bitmap(
  x,
  ...,
  direction = "left-to-right, top-to-bottom",
  font = bm_font(),
  hjust = "left",
  vjust = "top",
  compose = TRUE,
  pua_combining = character(0)
)

## S3 method for class 'grob'
as_bm_bitmap(
  x,
  ...,
  width = 8L,
  height = 16L,
  png_device = NULL,
  threshold = 0.25
)

Arguments

x

An object that can reasonably be coerced to a bm_bitmap() object.

...

Further arguments passed to or from other methods.

direction

For purely horizontal binding either "left-to-right" (default) or its aliases "ltr" and "lr" OR "right-to-left" or its aliases "rtl" and "rl". For purley vertical binding either "top-to-bottom" (default) or its aliases "ttb" and "tb" OR "bottom-to-top" or its aliases "btt" and "bt". For character vectors of length greater than one: for first horizontal binding within values in the vector and then vertical binding across values in the vector "left-to-right, top-to-bottom" (default) or its aliases "lrtb" and "lr-tb"; "left-to-right, bottom-to-top" or its aliases "lrbt" and "lr-bt"; "right-to-left, top-to-bottom" or its aliases "rltb" and "rl-tb"; or "right-to-left, bottom-to-top" or its aliases "rlbt" and "rl-bt". For first vertical binding within values in the vector and then horizontal binding across values "top-to-bottom, left-to-right" or its aliases "tblr" and "tb-lr"; "top-to-bottom, right-to-left" or its aliases "tbrl" and "tb-rl"; "bottom-to-top, left-to-right" or its aliases "btlr" and "bt-lr"; or "bottom-to-top, right-to-left" or its aliases "btrl" and "bt-rl". The direction argument is not case-sensitive.

font

A bm_font() object that contains all the characters within x.

hjust

Used by bm_extend() if bitmap widths are different.

vjust

Used by bm_extend() if bitmap heights are different.

compose

Compose graphemes using bm_compose().

pua_combining

Passed to bm_compose().

width

Desired width of bitmap

height

Desired height of bitmap

png_device

A function taking arguments filename, width, and height that starts a graphics device that saves a png image with a transparent background. By default will use ragg::agg_png() if available else the “cairo” version of grDevices::png() if available else just grDevices::png().

threshold

If any png channel weakly exceeds this threshold (on an interval from zero to one) then the pixel is determined to be “black”.

Value

A bm_bitmap() object.

See Also

bm_bitmap()

Examples

 space_matrix <- matrix(0L, nrow = 16L, ncol = 16L)
 space_glyph <- as_bm_bitmap(space_matrix)
 is_bm_bitmap(space_glyph)
  font_file <- system.file("fonts/fixed/4x6.yaff.gz", package = "bittermelon")
  font <- read_yaff(font_file)
  bm <- as_bm_bitmap("RSTATS", font = font)
  print(bm, px = px_ascii)
  bm <- as_bm_bitmap("RSTATS", direction = "top-to-bottom", font = font)
  print(bm, px = px_ascii)

 if (require("grid") && capabilities("png")) {
   circle <- as_bm_bitmap(circleGrob(r = 0.25), width = 16L, height = 16L)
   print(circle, px = c(".", "@"))

   inverted_exclamation <- as_bm_bitmap(textGrob("!", rot = 180),
                                        width = 8L, height = 16L)
   print(inverted_exclamation, px = c(".", "@"))
 }

bittermelon documentation built on Feb. 16, 2023, 8:08 p.m.