pptx_rs/opc/package.rs
1//! `OpcPackage`:包加载/保存。
2//!
3//! 本文件是 OPC 容器层的入口。它把"加载/保存一个 `.pptx`"和"注册 part +
4//! 维护 Content-Types + 维护关系链"三个动作统一到 [`OpcPackage`] 一个类型上。
5//!
6//! # 加载流程
7//!
8//! 1. 打开文件 → `zip::ZipArchive`;
9//! 2. 读取 `[Content_Types].xml` → `ContentTypes` 模型;
10//! 3. 遍历 zip 全部条目,把每个 part 装入 `parts: BTreeMap<PartName, Part>`;
11//! 4. 关系文件 `.rels` 同样作为 part 装入(content-type 固定为
12//! `application/vnd...relationships+xml`)。
13//!
14//! # 保存流程
15//!
16//! 1. 创建 `zip::ZipWriter`;
17//! 2. 写 `[Content_Types].xml`(序列化 `ContentTypes`);
18//! 3. 按 partname 顺序遍历 `parts`,逐个写入 zip;
19//! 4. 关闭 zip。
20//!
21//! # 设计取舍
22//!
23//! - **不维护反向关系索引**:本结构只持有"由 partname 找 part"的正向映射;
24//! 反向"由 partname 找关系链"由调用方在 `Relationships` 上自行迭代。
25//! - **`BTreeMap` 而非 `HashMap`**:让 `iter_parts()` 总是按 partname 字典序
26//! 输出,便于 byte-diff 测试与稳定写入顺序。
27//! - **不解析 `.rels`**:关系文件以原始 blob 形式保留,调用方在需要时
28//! 调用 `Relationships::from_xml` 显式解析。
29//!
30//! # 实现说明
31//!
32//! 自 v0.5.0 起改为 re-export [`ooxml_core::opc::package`] 的内容
33//! (`OpcPackage` / `derive_content_type` / `parse_content_types_public` /
34//! `rels_partname_for` / `next_rid`),仅保留 PPTX 特有的 Content-Type
35//! 常量于本 crate 的 [`ct`] 子模块,由 PresentationML 专属场景引用。
36
37pub use ooxml_core::opc::package::{
38 derive_content_type, next_rid, parse_content_types_public, rels_partname_for, OpcPackage,
39};
40
41/// 标准 Content-Type 常量集合(PPTX 特有部分 + 通用部分 re-export)。
42///
43/// 通用部分(`RELATIONSHIPS` / `THEME` / `CORE_PROPS` / `APP_PROPS` / `CUSTOM_PROPS` /
44/// `CHART` / `OLE_OBJECT` / `SPREADSHEET_XLSX` / `VIDEO_MP4` / `AUDIO_MP3` /
45/// `DIAGRAM_DATA` / `DIAGRAM_LAYOUT` / `DIAGRAM_QUICK_STYLE` / `DIAGRAM_COLORS`)
46/// 从 [`ooxml_core::opc::package::ct`] re-export;PPTX 特有部分(`PRESENTATION` /
47/// `SLIDE` / `SLIDE_LAYOUT` / `SLIDE_MASTER` / `NOTES_SLIDE` / `NOTES_MASTER` /
48/// `COMMENTS` / `COMMENT_AUTHORS`)保留在本模块,因为这些 Content-Type 仅在
49/// PresentationML 上下文中出现,不属于 OOXML 三件套共享的格式无关基座。
50///
51/// 这些常量与 ECMA-376 / OOXML 规范一一对应,使用 `pub const` 暴露
52/// 便于在序列化时直接引用而无需硬编码字符串。
53pub mod ct {
54 /// 通用 Content-Type 常量(re-export from ooxml-core)。
55 ///
56 /// 包含 `RELATIONSHIPS` / `THEME` / `CORE_PROPS` / `APP_PROPS` / `CUSTOM_PROPS` /
57 /// `CHART` / `OLE_OBJECT` / `SPREADSHEET_XLSX` / `VIDEO_MP4` / `AUDIO_MP3` /
58 /// `DIAGRAM_DATA` / `DIAGRAM_LAYOUT` / `DIAGRAM_QUICK_STYLE` / `DIAGRAM_COLORS`。
59 pub use ooxml_core::opc::package::ct::*;
60
61 /// 主演示文稿:`.../presentationml.presentation.main+xml`。
62 pub const PRESENTATION: &str =
63 "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml";
64 /// 幻灯片:`.../presentationml.slide+xml`。
65 pub const SLIDE: &str =
66 "application/vnd.openxmlformats-officedocument.presentationml.slide+xml";
67 /// 幻灯片布局:`.../presentationml.slideLayout+xml`。
68 pub const SLIDE_LAYOUT: &str =
69 "application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml";
70 /// 幻灯片母版:`.../presentationml.slideMaster+xml`。
71 pub const SLIDE_MASTER: &str =
72 "application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml";
73 /// 备注页:`.../presentationml.notesSlide+xml`。
74 ///
75 /// python-pptx 中由 `Slide.notes_slide` 隐式管理。
76 pub const NOTES_SLIDE: &str =
77 "application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml";
78 /// 备注母版:`.../presentationml.notesMaster+xml`(`/ppt/notesMasters/notesMasterN.xml`,TODO-045)。
79 ///
80 /// 对应 OOXML 中 `<p:notesMaster>` 根元素,被 `presentation.xml`
81 /// 的 `<p:notesMasterIdLst>` 引用。
82 pub const NOTES_MASTER: &str =
83 "application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml";
84 /// 幻灯片评论:`.../presentationml.comments+xml`(`/ppt/comments/commentN.xml`)。
85 ///
86 /// 对应 OOXML 中 `<p:cmLst>` 根元素,命名空间为
87 /// `http://schemas.openxmlformats.org/presentationml/2006/main`。
88 pub const COMMENTS: &str =
89 "application/vnd.openxmlformats-officedocument.presentationml.comments+xml";
90 /// 评论作者列表:`.../presentationml.commentAuthors+xml`(`/ppt/commentAuthors.xml`)。
91 ///
92 /// 全局共享的作者清单,对应 `<p:cmAuthorLst>` 根元素。
93 pub const COMMENT_AUTHORS: &str =
94 "application/vnd.openxmlformats-officedocument.presentationml.commentAuthors+xml";
95}