use std::fmt;
use crate::geometry::{DevicePixels, Points, Size};
#[path = "svg/sniff.rs"]
mod sniff;
#[derive(Debug, Clone, PartialEq, Default)]
#[non_exhaustive]
pub struct Raster {
pub width: u32,
pub height: u32,
pub pixels: Vec<u8>,
pub size: Size<Points>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
Unsupported,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"SVG images need the feature `svg`, which this runtime was built without"
)
}
}
impl std::error::Error for Error {}
pub fn sniff(bytes: &[u8]) -> bool {
sniff::sniff_text(bytes)
}
pub fn reported_size(size: Size<Points>) -> Size<DevicePixels> {
let whole = |p: Points| DevicePixels(p.0.round().clamp(1.0, i32::MAX as f32) as i32);
Size::new(whole(size.width), whole(size.height))
}
pub fn size(_bytes: &[u8]) -> Result<Size<Points>, Error> {
Err(Error::Unsupported)
}
pub fn rasterize(_bytes: &[u8], _max_px: u32) -> Result<Raster, Error> {
Err(Error::Unsupported)
}
pub fn rasterize_covering(_bytes: &[u8], _px: u32) -> Result<Raster, Error> {
Err(Error::Unsupported)
}
pub fn rasterize_scaled(_bytes: &[u8], _scale: f32) -> Result<Raster, Error> {
Err(Error::Unsupported)
}
pub fn rasterize_oversampled(_bytes: &[u8]) -> Result<Raster, Error> {
Err(Error::Unsupported)
}