easyofd_core/graphics2d/
ofd_page_graphics_configuration.rs1#[derive(Debug, Clone)]
15pub struct OfdPageGraphicsConfiguration {
16 pub dpi_x: u32,
18 pub dpi_y: u32,
20 pub color_depth: u32,
22}
23
24impl OfdPageGraphicsConfiguration {
25 #[must_use]
27 pub fn new() -> Self {
28 Self {
29 dpi_x: 96,
30 dpi_y: 96,
31 color_depth: 24,
32 }
33 }
34
35 #[must_use]
37 pub fn dpi(mut self, dpi: u32) -> Self {
38 self.dpi_x = dpi;
39 self.dpi_y = dpi;
40 self
41 }
42
43 #[must_use]
45 pub fn dpi_x(mut self, dpi: u32) -> Self {
46 self.dpi_x = dpi;
47 self
48 }
49
50 #[must_use]
52 pub fn dpi_y(mut self, dpi: u32) -> Self {
53 self.dpi_y = dpi;
54 self
55 }
56
57 #[must_use]
59 pub fn color_depth(mut self, depth: u32) -> Self {
60 self.color_depth = depth;
61 self
62 }
63}
64
65impl Default for OfdPageGraphicsConfiguration {
66 fn default() -> Self {
67 Self::new()
68 }
69}
70
71#[cfg(test)]
72mod tests {
73 use super::*;
74
75 #[test]
76 fn test_new_defaults() {
77 let c = OfdPageGraphicsConfiguration::new();
78 assert_eq!(c.dpi_x, 96);
79 assert_eq!(c.dpi_y, 96);
80 assert_eq!(c.color_depth, 24);
81 }
82
83 #[test]
84 fn test_builder() {
85 let c = OfdPageGraphicsConfiguration::new().dpi(300).color_depth(32);
86 assert_eq!(c.dpi_x, 300);
87 assert_eq!(c.dpi_y, 300);
88 assert_eq!(c.color_depth, 32);
89 }
90
91 #[test]
92 fn test_separate_dpi() {
93 let c = OfdPageGraphicsConfiguration::new().dpi_x(150).dpi_y(200);
94 assert_eq!(c.dpi_x, 150);
95 assert_eq!(c.dpi_y, 200);
96 }
97
98 #[test]
99 fn test_default() {
100 let c = OfdPageGraphicsConfiguration::default();
101 assert_eq!(c.dpi_x, 96);
102 }
103}