Skip to main content

easyofd_core/
consts.rs

1//! OFD 标准常量定义。
2//!
3//! 对应 Java: org.ofdrw.core.Const
4//!
5//! 定义 OFD 标准中使用的常量,包括命名空间 URI、元素名和属性名。
6
7/// OFD 命名空间 URI。
8///
9/// 对应 Java: org.ofdrw.core.Const#OFD_NS
10pub const OFD_NAMESPACE: &str = "http://www.ofdspec.org/2016";
11
12/// OFD 元素前缀。
13pub const OFD_PREFIX: &str = "ofd";
14
15/// OFD 文档根元素名。
16pub const OFD_ROOT_ELEMENT: &str = "OFD";
17
18/// 文档根元素名。
19pub const DOCUMENT_ELEMENT: &str = "Document";
20
21/// 页面元素名。
22pub const PAGE_ELEMENT: &str = "Page";
23
24/// 页面树元素名。
25pub const PAGES_ELEMENT: &str = "Pages";
26
27/// 文档体元素名。
28pub const DOC_BODY_ELEMENT: &str = "DocBody";
29
30/// 资源元素名。
31pub const RES_ELEMENT: &str = "Res";
32
33/// 默认页面宽度(mm,A4)。
34pub const DEFAULT_PAGE_WIDTH_MM: f64 = 210.0;
35
36/// 默认页面高度(mm,A4)。
37pub const DEFAULT_PAGE_HEIGHT_MM: f64 = 297.0;
38
39/// OFD 版本号。
40pub const OFD_VERSION: &str = "1.0";
41
42/// 文本对象元素名。
43pub const TEXT_OBJECT_ELEMENT: &str = "TextObject";
44
45/// 路径对象元素名。
46pub const PATH_OBJECT_ELEMENT: &str = "PathObject";
47
48/// 图像对象元素名。
49pub const IMAGE_OBJECT_ELEMENT: &str = "ImageObject";
50
51/// 复合对象元素名。
52pub const COMPOSITE_OBJECT_ELEMENT: &str = "CompositeObject";
53
54/// 图层元素名。
55pub const LAYER_ELEMENT: &str = "Layer";
56
57/// 签名元素名。
58pub const SIGNATURE_ELEMENT: &str = "Signature";
59
60/// 印章注释元素名。
61pub const STAMP_ANNOT_ELEMENT: &str = "StampAnnot";
62
63/// 附件元素名。
64pub const ATTACHMENT_ELEMENT: &str = "Attachment";
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_ofd_namespace() {
72        assert_eq!(OFD_NAMESPACE, "http://www.ofdspec.org/2016");
73    }
74
75    #[test]
76    fn test_default_page_size() {
77        assert!((DEFAULT_PAGE_WIDTH_MM - 210.0).abs() < f64::EPSILON);
78        assert!((DEFAULT_PAGE_HEIGHT_MM - 297.0).abs() < f64::EPSILON);
79    }
80
81    #[test]
82    fn test_element_names() {
83        assert_eq!(OFD_ROOT_ELEMENT, "OFD");
84        assert_eq!(PAGE_ELEMENT, "Page");
85        assert_eq!(TEXT_OBJECT_ELEMENT, "TextObject");
86    }
87}