Skip to main content

easyofd_reader/model/
stamp_annot_vo.rs

1//! 签章注释视图对象。
2//!
3//! 对应 Java: org.ofdrw.reader.model.StampAnnotVo
4//!
5//! 已废弃:Java 原始类标记为 `@Deprecated`,建议使用 `StampAnnotEntity`。
6
7/// 签章注释视图对象,包含签章注释列表和印章图片数据。
8///
9/// 对应 Java: `org.ofdrw.reader.model.StampAnnotVo`
10///
11/// **废弃**:Java 原始类标记为 `@Deprecated`,
12/// 建议使用 [`StampAnnotEntity`](easyofd_core::StampAnnotEntity)。
13#[derive(Debug, Clone)]
14#[deprecated(since = "1.0.0", note = "使用 easyofd_core::StampAnnotEntity 替代")]
15#[allow(deprecated)]
16pub struct StampAnnotVo {
17    /// 签章注释的 XML 描述列表。
18    pub stamp_annots: Vec<String>,
19    /// 印章图片的原始字节。
20    pub img_byte: Vec<u8>,
21    /// 印章图片类型(如 "PNG"、"JPEG")。
22    pub image_type: String,
23}
24
25#[allow(deprecated)]
26impl StampAnnotVo {
27    /// 创建新的签章注释视图对象。
28    #[must_use]
29    pub fn new() -> Self {
30        Self {
31            stamp_annots: Vec::new(),
32            img_byte: Vec::new(),
33            image_type: String::new(),
34        }
35    }
36
37    /// 设置印章图片数据。
38    pub fn set_img_byte(&mut self, data: Vec<u8>) {
39        self.img_byte = data;
40    }
41
42    /// 设置印章图片类型。
43    pub fn set_image_type(&mut self, image_type: impl Into<String>) {
44        self.image_type = image_type.into();
45    }
46
47    /// 添加签章注释描述。
48    pub fn add_stamp_annot(&mut self, annot: impl Into<String>) {
49        self.stamp_annots.push(annot.into());
50    }
51}
52
53#[allow(deprecated)]
54impl Default for StampAnnotVo {
55    fn default() -> Self {
56        Self::new()
57    }
58}
59
60#[allow(deprecated)]
61#[cfg(test)]
62mod tests {
63    #[allow(deprecated)]
64    use super::*;
65
66    #[test]
67    #[allow(deprecated)]
68    fn test_stamp_annot_vo_new() {
69        let vo = StampAnnotVo::new();
70        assert!(vo.stamp_annots.is_empty());
71        assert!(vo.img_byte.is_empty());
72        assert!(vo.image_type.is_empty());
73    }
74
75    #[test]
76    #[allow(deprecated)]
77    fn test_stamp_annot_vo_setters() {
78        let mut vo = StampAnnotVo::new();
79        vo.set_img_byte(vec![0x89, 0x50, 0x4E, 0x47]);
80        vo.set_image_type("PNG");
81        vo.add_stamp_annot("<StampAnnot/>");
82        assert_eq!(vo.img_byte.len(), 4);
83        assert_eq!(vo.image_type, "PNG");
84        assert_eq!(vo.stamp_annots.len(), 1);
85    }
86}