easyofd_core/graphics2d/
ofd_page_graphics_device.rs1use super::OfdPageGraphicsConfiguration;
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub enum GraphicsDeviceType {
13 Screen,
15 Printer,
17 Image,
19}
20
21#[derive(Debug, Clone)]
28pub struct OfdPageGraphicsDevice {
29 pub device_type: GraphicsDeviceType,
31 pub name: Option<String>,
33 pub configuration: OfdPageGraphicsConfiguration,
35}
36
37impl OfdPageGraphicsDevice {
38 #[must_use]
40 pub fn new() -> Self {
41 Self {
42 device_type: GraphicsDeviceType::Image,
43 name: None,
44 configuration: OfdPageGraphicsConfiguration::new(),
45 }
46 }
47
48 #[must_use]
50 pub fn with_type(device_type: GraphicsDeviceType) -> Self {
51 Self {
52 device_type,
53 name: None,
54 configuration: OfdPageGraphicsConfiguration::new(),
55 }
56 }
57
58 #[must_use]
60 pub fn name(mut self, name: impl Into<String>) -> Self {
61 self.name = Some(name.into());
62 self
63 }
64
65 #[must_use]
67 pub fn configuration(mut self, config: OfdPageGraphicsConfiguration) -> Self {
68 self.configuration = config;
69 self
70 }
71
72 #[must_use]
74 pub fn device_type(&self) -> GraphicsDeviceType {
75 self.device_type
76 }
77}
78
79impl Default for OfdPageGraphicsDevice {
80 fn default() -> Self {
81 Self::new()
82 }
83}
84
85#[cfg(test)]
86mod tests {
87 use super::*;
88
89 #[test]
90 fn test_new_default() {
91 let d = OfdPageGraphicsDevice::new();
92 assert_eq!(d.device_type(), GraphicsDeviceType::Image);
93 assert!(d.name.is_none());
94 }
95
96 #[test]
97 fn test_with_type() {
98 let d = OfdPageGraphicsDevice::with_type(GraphicsDeviceType::Screen);
99 assert_eq!(d.device_type(), GraphicsDeviceType::Screen);
100 }
101
102 #[test]
103 fn test_builder() {
104 let config = OfdPageGraphicsConfiguration::new().dpi(300);
105 let d = OfdPageGraphicsDevice::new()
106 .name("Printer1")
107 .configuration(config);
108 assert_eq!(d.name.as_deref(), Some("Printer1"));
109 assert_eq!(d.configuration.dpi_x, 300);
110 }
111
112 #[test]
113 fn test_device_type_variants() {
114 assert_ne!(GraphicsDeviceType::Screen, GraphicsDeviceType::Printer);
115 assert_ne!(GraphicsDeviceType::Printer, GraphicsDeviceType::Image);
116 }
117
118 #[test]
119 fn test_default() {
120 let d = OfdPageGraphicsDevice::default();
121 assert_eq!(d.device_type(), GraphicsDeviceType::Image);
122 }
123}