if (FALSE) {
data("font_example")
## make a raster that we can use to create a bitmap font
font9.rast <- as.raster(getAmigaBitmapFont(font_example, 9))
## note the glyphs and the order in which they are included in
## the raster image:
plot(font9.rast)
## let's build a simple font, using only the first few glyphs
## in the raster:
font9 <- rasterToAmigaBitmapFont(
## 'x' needs the raster image:
x = font9.rast,
## 'glyphs' are the graphical representation of the characters
## that we will include in our font. We will only use the
## first 7 characters in the raster image:
glyphs = " !\"#$%&",
## We will use the '&' glyph to represent all characters that
## are not specified in the font:
default_glyph = "&",
## The raster image is 9 pixels tall, as will be the font.
## Let's use 7 as the base (it needs to be less than the height)
baseline = 7,
## Let's define the width in pixels for each of the 7
## characters. This is their width in the raster image:
glyph_width = c(0, 1, 3, 6, 5, 5, 5),
## Let's define the space the character should take in pixels
## when it is used to format text:
glyph_space = c(4, 2, 4, 7, 6, 6, 6),
## the raster uses white as background colour and black as
## foreground:
palette = c("white", "black")
)
## note that for all characters that are not specified,
## the default glyph ('&') is used:
plot(font9, text = "!@#$%ABCD")
## Let's take a subset from the font's bitmap (rasteer):
font9abc.rast <- font9.rast[,263:282]
## as you can see this bitmap only contains the lowercase
## characters 'a', 'b', 'c', 'd' and 'e':
plot(font9abc.rast)
font9.abc <- rasterToAmigaBitmapFont(
x = font9abc.rast,
## Each glyph in the image can be represented by a single
## element in a list. By specifying multiple characters in
## each element, you can recycle a glyph to represent different
## characters. So in this case, the glyph 'a' is used for
## all the accented variants of the character 'a'.
glyphs = list("a\xE0\xE1\xE2\xE3\xE4\xE5",
"b",
"c\xA2\xE7",
"d",
"e\xE8\xE9\xEA\xEB"),
default_glyph = "c", ## 'c' is used as default glyph for all other characters
baseline = 7,
glyph_width = c(4, 4, 4, 4, 4),
glyph_space = c(5, 5, 5, 5, 5),
palette = c("white", "black")
)
## see what happens when you format text using the font we just created:
plot(font9.abc, text = "a\xE0\xE1\xE2\xE3\xE4\xE5bc\xA2\xE7de\xE8\xE9\xEA\xEB, foo bar")
}
Run the code above in your browser using DataLab