Skip to main content

lichtung_plot/spec/
output.rs

1//! Call-local PNG publication options.
2
3/// CSS pixel density used by SVG renderers.
4pub(crate) const SVG_CSS_DPI: f32 = 96.0;
5
6/// PNG export options for rasterizing the canonical SVG scene.
7#[derive(Debug, Clone, Copy, PartialEq)]
8pub struct PngOptions {
9    /// How the output PNG pixel dimensions are chosen.
10    pub sizing: PngSizing,
11    /// PNG encoder compression preset.
12    pub compression: PngCompression,
13}
14
15impl Default for PngOptions {
16    fn default() -> Self {
17        Self {
18            sizing: PngSizing::Dpi(300.0),
19            compression: PngCompression::Balanced,
20        }
21    }
22}
23
24/// Mutually exclusive PNG sizing modes.
25#[derive(Debug, Clone, Copy, PartialEq)]
26pub enum PngSizing {
27    /// Preserve the SVG canvas pixel dimensions.
28    Source,
29    /// Render at a print-oriented DPI, treating SVG CSS pixels as 96 DPI.
30    /// Also writes matching DPI metadata to the PNG file.
31    Dpi(f32),
32    /// Multiply SVG canvas width and height by this scale factor.
33    Scale(f32),
34    /// Set the output width in pixels and preserve aspect ratio.
35    Width(u32),
36    /// Set the output height in pixels and preserve aspect ratio.
37    Height(u32),
38}
39
40/// High-level PNG compression presets.
41#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
42pub enum PngCompression {
43    /// Do not compress. Fastest, largest files.
44    None,
45    /// Prefer encoding speed over file size.
46    Fast,
47    /// Balance encoding speed and file size.
48    #[default]
49    Balanced,
50    /// Spend more time for smaller files.
51    High,
52}