mod glyphs;
pub use glyphs::*;
pub struct Glyph {
pub name: &'static str,
pub strokes: &'static str,
pub fills: &'static str,
}
impl Glyph {
pub fn svg(&self, px: f32, class: &str) -> String {
let points = px / 1.2;
let width = (0.6 + 0.04 * points) * 24.0 / px;
let mut out = format!(
"<svg class=\"{class}\" viewBox=\"0 0 24 24\" fill=none stroke=currentColor \
stroke-width=\"{width:.2}\" stroke-linecap=square stroke-linejoin=miter aria-hidden=true>"
);
if !self.strokes.is_empty() {
out.push_str(&format!("<path d=\"{}\"/>", self.strokes));
}
if !self.fills.is_empty() {
out.push_str(&format!(
"<path d=\"{}\" fill=currentColor stroke=none/>",
self.fills
));
}
out.push_str("</svg>");
out
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_set_is_whole_and_drawn_square() {
assert!(ALL.len() > 100);
for g in ALL {
assert!(
!g.strokes.is_empty() || !g.fills.is_empty(),
"{} has no shape",
g.name
);
}
let svg = PLAY.svg(18.0, "x");
assert!(svg.contains("stroke-linecap=square") && svg.contains("class=\"x\""));
assert!(HEART_FILLED.svg(15.0, "").contains("fill=currentColor"));
}
}