1#![doc = include_str!("../README.md")]
2#![forbid(unsafe_code)]
3#![deny(missing_docs)]
4
5mod codes;
6mod html;
7mod layout;
8#[cfg(feature = "png")]
9mod png;
10mod svg;
11mod text;
12
13use serde::{Deserialize, Serialize};
14
15pub use html::{render_html, render_html_document, STYLESHEET};
16#[cfg(feature = "png")]
17pub use png::{render_png, PngError, MAX_PNG_HEIGHT};
18pub use svg::render_svg;
19pub use text::{to_text, to_text_with};
20
21pub const FONT_LICENSE: &str = include_str!("../fonts/LICENSE");
24
25#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
33#[serde(try_from = "u16", into = "u16")]
34pub enum PaperWidth {
35 Mm58,
37 #[default]
39 Mm80,
40}
41
42impl PaperWidth {
43 pub fn columns(self) -> (u32, u32) {
45 match self {
46 PaperWidth::Mm58 => (32, 42),
47 PaperWidth::Mm80 => (48, 64),
48 }
49 }
50
51 pub fn millimetres(self) -> u16 {
53 match self {
54 PaperWidth::Mm58 => 58,
55 PaperWidth::Mm80 => 80,
56 }
57 }
58
59 pub fn dots(self) -> u32 {
61 self.columns().0 * layout::DOTS_PER_COLUMN
62 }
63}
64
65impl TryFrom<u16> for PaperWidth {
66 type Error = String;
67
68 fn try_from(mm: u16) -> Result<Self, String> {
69 match mm {
70 58 => Ok(PaperWidth::Mm58),
71 80 => Ok(PaperWidth::Mm80),
72 other => Err(format!("paper width must be 58 or 80, not {other}")),
73 }
74 }
75}
76
77impl From<PaperWidth> for u16 {
78 fn from(paper: PaperWidth) -> u16 {
79 paper.millimetres()
80 }
81}
82
83#[derive(Clone, Copy, Debug, PartialEq, Eq)]
85pub struct RenderOptions {
86 pub paper: PaperWidth,
88 pub show_unknown: bool,
90}
91
92impl Default for RenderOptions {
93 fn default() -> Self {
94 Self {
95 paper: PaperWidth::Mm80,
96 show_unknown: true,
97 }
98 }
99}