Skip to main content

ofd_core/model/
annotation.rs

1//! 注释(见 GB/T 33190—2016 第 15 章)。
2//!
3//! 注释是独立于页面内容之外、叠加绘制在页面之上的图元,最典型者为电子印章
4//! (`Type="Stamp"`)的签章外观。其组织分两级:
5//!
6//! - 注释入口文件(`Document.xml` 中 `Annotations` 指向,见表 49):按页列出
7//!   每页注释所在的文件位置;
8//! - 页注释文件 [`PageAnnot`](见表 50):含若干 [`Annot`],每个注释通过
9//!   [`Appearance`] 给出其外观——一组与页面图元相同的可绘制对象。
10//!
11//! 渲染时,注释外观叠加在页面内容与前景模板之上;`Appearance` 的 `Boundary`
12//! 给出外观在页面坐标系中的位置,其内部图元对象坐标相对该边界左上角。
13
14use serde::{Deserialize, Serialize};
15
16use crate::model::graphics::PageBlock;
17use crate::types::{StBox, StId, StLoc, StRefId};
18
19/// 注释入口文件根节点(`Document.xml` 中 `Annotations` 指向;见表 49)。
20#[derive(Debug, Clone, Default, Deserialize, Serialize)]
21pub struct Annotations {
22    /// 按页组织的注释引用,每页一个节点。
23    #[serde(rename = "Page", default)]
24    pub pages: Vec<AnnotPageRef>,
25}
26
27/// 某一页的注释文件引用(见表 49)。
28#[derive(Debug, Clone, Default, Deserialize, Serialize)]
29pub struct AnnotPageRef {
30    /// 关联的页对象标识(必选)。
31    #[serde(rename = "@PageID")]
32    pub page_id: StRefId,
33    /// 指向该页的页注释文件(必选)。
34    #[serde(rename = "FileLoc")]
35    pub file_loc: StLoc,
36}
37
38/// 页注释文件根节点(见表 50)。
39#[derive(Debug, Clone, Default, Deserialize, Serialize)]
40pub struct PageAnnot {
41    /// 该页上的注释列表。
42    #[serde(rename = "Annot", default)]
43    pub annots: Vec<Annot>,
44}
45
46/// `CT_Annot`:单个注释(见表 51)。
47#[derive(Debug, Clone, Default, Deserialize, Serialize)]
48pub struct Annot {
49    /// 注释标识(可选)。
50    #[serde(rename = "@ID")]
51    pub id: Option<StId>,
52    /// 注释类型,如 `Stamp`/`Link`/`Highlight` 等(可选)。
53    #[serde(rename = "@Type")]
54    pub annot_type: Option<String>,
55    /// 是否可见,默认 `true`(可选)。
56    #[serde(rename = "@Visible")]
57    pub visible: Option<bool>,
58    /// 注释的外观描述(可选)。
59    #[serde(rename = "Appearance")]
60    pub appearance: Option<Appearance>,
61}
62
63/// `CT_Appearance`:注释外观(见表 51)。
64///
65/// 本质是一组与页面图元相同的可绘制对象(`CT_PageBlock`),其坐标相对
66/// [`boundary`](Appearance::boundary) 左上角。
67#[derive(Debug, Clone, Default, Deserialize, Serialize)]
68pub struct Appearance {
69    /// 注释外观在页面坐标系中的边界(必选)。
70    #[serde(rename = "@Boundary", default)]
71    pub boundary: StBox,
72    /// 外观内的可绘制对象,按出现顺序绘制。
73    #[serde(rename = "$value", default)]
74    pub objects: Vec<PageBlock>,
75}