#![deny(missing_docs)]
use std::borrow::Cow;
#[rustfmt::skip]
mod gen;
mod int_map;
pub use crate::gen::*;
pub use crate::int_map::*;
impl Encoding {
pub fn data(&self) -> Option<&'static [char; 128]> {
gen::encoding_data(*self)
}
}
#[derive(Debug)]
#[non_exhaustive]
pub struct Profile<'a> {
pub name: Cow<'a, str>,
pub vendor: Cow<'a, str>,
pub features: Features,
pub code_pages: Cow<'a, IntMap<Encoding>>,
pub colors: Cow<'a, IntMap<Color>>,
pub fonts: Cow<'a, IntMap<FontInfo>>,
pub media: Media,
}
impl<'a> Profile<'a> {
pub const fn new(name: Cow<'a, str>, vendor: Cow<'a, str>) -> Self {
Self {
name,
vendor,
features: Features::new(),
code_pages: Cow::Borrowed(IntMap::empty()),
colors: Cow::Borrowed(IntMap::empty()),
fonts: Cow::Borrowed(IntMap::empty()),
media: Media::new(None, None),
}
}
pub const fn with_features(mut self, features: Features) -> Self {
self.features = features;
self
}
pub fn with_code_pages(mut self, code_pages: Cow<'a, IntMap<Encoding>>) -> Self {
self.code_pages = code_pages;
self
}
pub fn with_colors(mut self, colors: Cow<'a, IntMap<Color>>) -> Self {
self.colors = colors;
self
}
pub fn with_fonts(mut self, fonts: Cow<'a, IntMap<FontInfo>>) -> Self {
self.fonts = fonts;
self
}
pub const fn with_media(mut self, media: Media) -> Self {
self.media = media;
self
}
}
#[derive(Copy, Clone, Debug)]
#[allow(missing_docs)]
pub enum Color {
Black,
Red,
Alternate,
}
#[derive(Debug)]
#[non_exhaustive]
pub struct FontInfo {
pub columns: u8,
}
#[derive(Copy, Clone, Debug, Default)]
pub struct Features(FeaturesInner);
impl Features {
const fn _with(mut self, flag: FeaturesInner, on: bool) -> Self {
self.0 = if on {
self.0.union(flag)
} else {
self.0.difference(flag)
};
self
}
}
#[derive(Debug, Default)]
#[non_exhaustive]
pub struct Media {
pub dpi: Option<u16>,
pub width: Option<Width>,
}
impl Media {
pub const fn new(dpi: Option<u16>, width: Option<Width>) -> Self {
Self { dpi, width }
}
}
#[derive(Debug)]
#[non_exhaustive]
pub struct Width {
pub mm: f32,
pub px: u16,
}
impl Width {
pub fn new(mm: f32, px: u16) -> Self {
Self { mm, px }
}
}