Function rasterize_glyph_mask

Source
pub fn rasterize_glyph_mask(font: &Font, ch: char, px_size: u32) -> Vec<u8> ⓘ
Expand description

Rasterizes a glyph into a square RGBA buffer (px_size × px_size, white mask + alpha).

The font is sampled at max(px_size, 8) pixels. Glyph pixels are centered, clipped to the requested square, and written as white RGB with font coverage in alpha. A zero size returns an empty vector.

§Panics

May panic if px_size * px_size * 4 overflows or cannot be allocated.

§Examples

use ailloli_ui_devicons_font::{DEVICON_FONT_BYTES, GENERIC_FILE_GLYPH};
use ailloli_ui_render_wgpu::icons::raster::rasterize_glyph_mask;
let font = fontdue::Font::from_bytes(DEVICON_FONT_BYTES,
    fontdue::FontSettings::default())?;
let rgba = rasterize_glyph_mask(&font, GENERIC_FILE_GLYPH, 8);
assert_eq!(rgba.len(), 8 * 8 * 4);