Function validate_app_icon

Source
pub fn validate_app_icon(icon: &AppIcon) -> Result<ValidatedIcon, IconError>
Expand description

Validates source size, XML/resource structure, square geometry, and visibility.

Validation accepts at most 4 MiB, requires an exact viewBox or viewbox attribute with four comma/ASCII-whitespace-separated f64 values and positive width/height, enforces relative squareness and both raw/parsed 8,192-pixel limits, parses through [usvg], then requires nonzero alpha in a 64-pixel preview. View-box origins may be any parseable numbers. The returned digest covers exact source bytes; the AppIcon source-path label is irrelevant.

§Errors

Returns the corresponding IconError at the first failed stage, including preview allocation. Error strings can embed parser text or rejected attributes.

§Examples

use ailloli_ui_core::AppIcon;
use ailloli_ui_icon::{validate_app_icon, IconError};
const GOOD: &[u8] = br#"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4 4"><circle cx="2" cy="2" r="2"/></svg>"#;
let validated = validate_app_icon(&AppIcon::from_static_svg(GOOD, "good.svg")).unwrap();
assert_eq!((validated.width, validated.height), (4.0, 4.0));
const BAD: &[u8] = br#"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4 2"><rect width="4" height="2"/></svg>"#;
assert!(matches!(
    validate_app_icon(&AppIcon::from_static_svg(BAD, "bad.svg")),
    Err(IconError::NonSquare(width, height)) if width == 4.0 && height == 2.0
));