#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BackendCapabilities {
pub name: &'static str,
pub vector_text: bool,
pub embedded_fonts: bool,
pub gradients: bool,
pub clipping: bool,
pub images: bool,
pub raster_only: bool,
pub multi_page: bool,
pub deterministic: bool,
}
impl BackendCapabilities {
pub const fn none(name: &'static str) -> Self {
Self {
name,
vector_text: false,
embedded_fonts: false,
gradients: false,
clipping: false,
images: false,
raster_only: false,
multi_page: false,
deterministic: false,
}
}
pub const fn vector(name: &'static str) -> Self {
Self {
name,
vector_text: true,
embedded_fonts: false,
gradients: true,
clipping: true,
images: true,
raster_only: false,
multi_page: true,
deterministic: true,
}
}
pub const fn raster(name: &'static str) -> Self {
Self {
name,
vector_text: false,
embedded_fonts: false,
gradients: true,
clipping: true,
images: true,
raster_only: true,
multi_page: false,
deterministic: false,
}
}
pub fn supports(&self, feature: BackendFeature) -> bool {
match feature {
BackendFeature::VectorText => self.vector_text,
BackendFeature::EmbeddedFonts => self.embedded_fonts,
BackendFeature::Gradients => self.gradients,
BackendFeature::Clipping => self.clipping,
BackendFeature::Images => self.images,
BackendFeature::MultiPage => self.multi_page,
BackendFeature::Deterministic => self.deterministic,
}
}
pub fn is_consistent(&self) -> bool {
!(self.raster_only && self.vector_text)
}
pub fn covers(&self, required: &[BackendFeature]) -> bool {
required.iter().all(|feature| self.supports(*feature))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BackendFeature {
VectorText,
EmbeddedFonts,
Gradients,
Clipping,
Images,
MultiPage,
Deterministic,
}
impl BackendFeature {
pub fn as_str(self) -> &'static str {
match self {
Self::VectorText => "vectorText",
Self::EmbeddedFonts => "embeddedFonts",
Self::Gradients => "gradients",
Self::Clipping => "clipping",
Self::Images => "images",
Self::MultiPage => "multiPage",
Self::Deterministic => "deterministic",
}
}
}