Skip to main content

easyofd_core/image/
ct_image.rs

1//! 图像对象。
2//!
3//! 对应 Java: org.ofdrw.core.image.CT_Image
4
5/// 图像对象。
6///
7/// 对应 Java: org.ofdrw.core.image.CT_Image
8#[allow(non_camel_case_types)]
9#[derive(Debug, Clone, PartialEq)]
10pub struct CT_Image {
11    /// 对象 ID。
12    pub id: u32,
13    /// 边界框 "x y width height"。
14    pub boundary: String,
15    /// 资源 ID(引用 MultiMedia 中的图像资源)。
16    pub resource_id: u32,
17    /// 是否插值绘制。
18    pub interpolate: bool,
19}
20
21impl CT_Image {
22    /// 创建图像对象。
23    #[must_use]
24    pub fn new(id: u32, boundary: impl Into<String>, resource_id: u32) -> Self {
25        Self {
26            id,
27            boundary: boundary.into(),
28            resource_id,
29            interpolate: false,
30        }
31    }
32
33    /// 设置插值绘制。
34    #[must_use]
35    pub fn interpolate(mut self, interpolate: bool) -> Self {
36        self.interpolate = interpolate;
37        self
38    }
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn ct_image_new() {
47        let img = CT_Image::new(1, "0 0 100 100", 5);
48        assert_eq!(img.id, 1);
49        assert_eq!(img.resource_id, 5);
50        assert!(!img.interpolate);
51    }
52
53    #[test]
54    fn ct_image_builder() {
55        let img = CT_Image::new(2, "10 20 50 50", 3).interpolate(true);
56        assert!(img.interpolate);
57    }
58}