ailloli_ui_render_wgpu/icons/devicons.rs
1//! Devicons rasterization (Nerd Font).
2
3use fontdue::Font;
4
5use super::raster::rasterize_glyph_mask;
6
7/// Rasterizes one Nerd Font Devicon into a square white RGBA alpha mask.
8///
9/// The output contains exactly `px_size * px_size * 4` bytes. Sizes below eight
10/// still allocate the requested square but rasterize the glyph at eight pixels,
11/// clipping it into that square.
12///
13/// # Examples
14///
15/// ```
16/// use ailloli_ui_devicons_font::{DEVICON_FONT_BYTES, GENERIC_FILE_GLYPH};
17/// use ailloli_ui_render_wgpu::icons::devicons::rasterize_devicon;
18/// let font = fontdue::Font::from_bytes(DEVICON_FONT_BYTES,
19/// fontdue::FontSettings::default())?;
20/// let rgba = rasterize_devicon(&font, GENERIC_FILE_GLYPH, 16);
21/// assert_eq!(rgba.len(), 16 * 16 * 4);
22/// # Ok::<(), &'static str>(())
23/// ```
24pub fn rasterize_devicon(font: &Font, ch: char, px_size: u32) -> Vec<u8> {
25 rasterize_glyph_mask(font, ch, px_size)
26}