Skip to main content

easyofd_reader/model/
ofd_document_vo.rs

1//! OFD 文档视图对象。
2//!
3//! 对应 Java: org.ofdrw.reader.model.OFDDocumentVo
4//!
5//! 已废弃:Java 原始类标记为 `@Deprecated`,建议使用 `DLOFDReader`。
6
7use super::AnnotionEntity;
8
9/// OFD 文档视图对象,包含文档的基本信息和页面列表。
10///
11/// 对应 Java: `org.ofdrw.reader.model.OFDDocumentVo`
12///
13/// **废弃**:Java 原始类标记为 `@Deprecated`。
14#[derive(Debug, Clone)]
15#[deprecated(since = "1.0.0", note = "使用 OfdReader 直接解析替代")]
16#[allow(deprecated)]
17pub struct OfdDocumentVo {
18    /// 文档路径。
19    pub doc_path: String,
20    /// 页面宽度(毫米)。
21    pub page_width: f64,
22    /// 页面高度(毫米)。
23    pub page_height: f64,
24    /// 注释列表。
25    pub annotations: Vec<AnnotionEntity>,
26}
27
28#[allow(deprecated)]
29impl OfdDocumentVo {
30    /// 创建新的文档视图对象。
31    #[must_use]
32    pub fn new(
33        doc_path: impl Into<String>,
34        page_width: f64,
35        page_height: f64,
36        annotations: Vec<AnnotionEntity>,
37    ) -> Self {
38        Self {
39            doc_path: doc_path.into(),
40            page_width,
41            page_height,
42            annotations,
43        }
44    }
45
46    /// 获取注释列表。
47    #[must_use]
48    pub fn annotations(&self) -> &[AnnotionEntity] {
49        &self.annotations
50    }
51}
52
53#[allow(deprecated)]
54#[cfg(test)]
55mod tests {
56    #[allow(deprecated)]
57    use super::*;
58
59    #[test]
60    #[allow(deprecated)]
61    fn test_ofd_document_vo_new() {
62        let vo = OfdDocumentVo::new("Doc_0", 210.0, 297.0, vec![]);
63        assert_eq!(vo.doc_path, "Doc_0");
64        assert!((vo.page_width - 210.0).abs() < f64::EPSILON);
65        assert!((vo.page_height - 297.0).abs() < f64::EPSILON);
66        assert!(vo.annotations.is_empty());
67    }
68
69    #[test]
70    #[allow(deprecated)]
71    fn test_ofd_document_vo_with_annotations() {
72        let ann = AnnotionEntity::new("page_0", vec!["<Annot/>".into()]);
73        let vo = OfdDocumentVo::new("Doc_0", 210.0, 297.0, vec![ann]);
74        assert_eq!(vo.annotations().len(), 1);
75    }
76}