1#![deny(missing_docs)]
4
5use std::borrow::Cow;
6
7#[rustfmt::skip]
8mod gen;
9mod int_map;
10
11pub use crate::gen::*;
12pub use crate::int_map::*;
13
14impl Encoding {
15 pub fn data(&self) -> Option<&'static [char; 128]> {
17 gen::encoding_data(*self)
18 }
19}
20
21#[derive(Debug)]
23#[non_exhaustive]
24pub struct Profile<'a> {
25 pub name: Cow<'a, str>,
27 pub vendor: Cow<'a, str>,
29 pub features: Features,
31 pub code_pages: Cow<'a, IntMap<Encoding>>,
33 pub colors: Cow<'a, IntMap<Color>>,
35 pub fonts: Cow<'a, IntMap<FontInfo>>,
37 pub media: Media,
39}
40
41impl<'a> Profile<'a> {
42 pub const fn new(name: Cow<'a, str>, vendor: Cow<'a, str>) -> Self {
46 Self {
47 name,
48 vendor,
49 features: Features::new(),
50 code_pages: Cow::Borrowed(IntMap::empty()),
51 colors: Cow::Borrowed(IntMap::empty()),
52 fonts: Cow::Borrowed(IntMap::empty()),
53 media: Media::new(None, None),
54 }
55 }
56
57 pub const fn with_features(mut self, features: Features) -> Self {
59 self.features = features;
60 self
61 }
62
63 pub fn with_code_pages(mut self, code_pages: Cow<'a, IntMap<Encoding>>) -> Self {
66 self.code_pages = code_pages;
67 self
68 }
69
70 pub fn with_colors(mut self, colors: Cow<'a, IntMap<Color>>) -> Self {
73 self.colors = colors;
74 self
75 }
76
77 pub fn with_fonts(mut self, fonts: Cow<'a, IntMap<FontInfo>>) -> Self {
80 self.fonts = fonts;
81 self
82 }
83
84 pub const fn with_media(mut self, media: Media) -> Self {
86 self.media = media;
87 self
88 }
89}
90
91#[derive(Copy, Clone, Debug)]
93#[allow(missing_docs)]
94pub enum Color {
95 Black,
96 Red,
97 Alternate,
98}
99
100#[derive(Debug)]
102#[non_exhaustive]
103pub struct FontInfo {
104 pub columns: u8,
106}
107
108#[derive(Copy, Clone, Debug, Default)]
110pub struct Features(FeaturesInner);
111
112impl Features {
113 const fn _with(mut self, flag: FeaturesInner, on: bool) -> Self {
114 self.0 = if on {
115 self.0.union(flag)
116 } else {
117 self.0.difference(flag)
118 };
119 self
120 }
121}
122
123#[derive(Debug, Default)]
125#[non_exhaustive]
126pub struct Media {
127 pub dpi: Option<u16>,
129 pub width: Option<Width>,
131}
132
133impl Media {
134 pub const fn new(dpi: Option<u16>, width: Option<Width>) -> Self {
136 Self { dpi, width }
137 }
138}
139
140#[derive(Debug)]
142#[non_exhaustive]
143pub struct Width {
144 pub mm: f32,
146 pub px: u16,
148}
149
150impl Width {
151 pub fn new(mm: f32, px: u16) -> Self {
153 Self { mm, px }
154 }
155}