pptx-rs2 0.5.0

Rust 版本的 PowerPoint .pptx 读写库, 对标 python-pptx
Documentation
//! `OpcPackage`:包加载/保存。
//!
//! 本文件是 OPC 容器层的入口。它把"加载/保存一个 `.pptx`"和"注册 part +
//! 维护 Content-Types + 维护关系链"三个动作统一到 [`OpcPackage`] 一个类型上。
//!
//! # 加载流程
//!
//! 1. 打开文件 → `zip::ZipArchive`;
//! 2. 读取 `[Content_Types].xml` → `ContentTypes` 模型;
//! 3. 遍历 zip 全部条目,把每个 part 装入 `parts: BTreeMap<PartName, Part>`;
//! 4. 关系文件 `.rels` 同样作为 part 装入(content-type 固定为
//!    `application/vnd...relationships+xml`)。
//!
//! # 保存流程
//!
//! 1. 创建 `zip::ZipWriter`;
//! 2. 写 `[Content_Types].xml`(序列化 `ContentTypes`);
//! 3. 按 partname 顺序遍历 `parts`,逐个写入 zip;
//! 4. 关闭 zip。
//!
//! # 设计取舍
//!
//! - **不维护反向关系索引**:本结构只持有"由 partname 找 part"的正向映射;
//!   反向"由 partname 找关系链"由调用方在 `Relationships` 上自行迭代。
//! - **`BTreeMap` 而非 `HashMap`**:让 `iter_parts()` 总是按 partname 字典序
//!   输出,便于 byte-diff 测试与稳定写入顺序。
//! - **不解析 `.rels`**:关系文件以原始 blob 形式保留,调用方在需要时
//!   调用 `Relationships::from_xml` 显式解析。
//!
//! # 实现说明
//!
//! 自 v0.5.0 起改为 re-export [`ooxml_core::opc::package`] 的内容
//! (`OpcPackage` / `derive_content_type` / `parse_content_types_public` /
//! `rels_partname_for` / `next_rid`),仅保留 PPTX 特有的 Content-Type
//! 常量于本 crate 的 [`ct`] 子模块,由 PresentationML 专属场景引用。

pub use ooxml_core::opc::package::{
    derive_content_type, next_rid, parse_content_types_public, rels_partname_for, OpcPackage,
};

/// 标准 Content-Type 常量集合(PPTX 特有部分 + 通用部分 re-export)。
///
/// 通用部分(`RELATIONSHIPS` / `THEME` / `CORE_PROPS` / `APP_PROPS` / `CUSTOM_PROPS` /
/// `CHART` / `OLE_OBJECT` / `SPREADSHEET_XLSX` / `VIDEO_MP4` / `AUDIO_MP3` /
/// `DIAGRAM_DATA` / `DIAGRAM_LAYOUT` / `DIAGRAM_QUICK_STYLE` / `DIAGRAM_COLORS`)
/// 从 [`ooxml_core::opc::package::ct`] re-export;PPTX 特有部分(`PRESENTATION` /
/// `SLIDE` / `SLIDE_LAYOUT` / `SLIDE_MASTER` / `NOTES_SLIDE` / `NOTES_MASTER` /
/// `COMMENTS` / `COMMENT_AUTHORS`)保留在本模块,因为这些 Content-Type 仅在
/// PresentationML 上下文中出现,不属于 OOXML 三件套共享的格式无关基座。
///
/// 这些常量与 ECMA-376 / OOXML 规范一一对应,使用 `pub const` 暴露
/// 便于在序列化时直接引用而无需硬编码字符串。
pub mod ct {
    /// 通用 Content-Type 常量(re-export from ooxml-core)。
    ///
    /// 包含 `RELATIONSHIPS` / `THEME` / `CORE_PROPS` / `APP_PROPS` / `CUSTOM_PROPS` /
    /// `CHART` / `OLE_OBJECT` / `SPREADSHEET_XLSX` / `VIDEO_MP4` / `AUDIO_MP3` /
    /// `DIAGRAM_DATA` / `DIAGRAM_LAYOUT` / `DIAGRAM_QUICK_STYLE` / `DIAGRAM_COLORS`。
    pub use ooxml_core::opc::package::ct::*;

    /// 主演示文稿:`.../presentationml.presentation.main+xml`。
    pub const PRESENTATION: &str =
        "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml";
    /// 幻灯片:`.../presentationml.slide+xml`。
    pub const SLIDE: &str =
        "application/vnd.openxmlformats-officedocument.presentationml.slide+xml";
    /// 幻灯片布局:`.../presentationml.slideLayout+xml`。
    pub const SLIDE_LAYOUT: &str =
        "application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml";
    /// 幻灯片母版:`.../presentationml.slideMaster+xml`。
    pub const SLIDE_MASTER: &str =
        "application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml";
    /// 备注页:`.../presentationml.notesSlide+xml`。
    ///
    /// python-pptx 中由 `Slide.notes_slide` 隐式管理。
    pub const NOTES_SLIDE: &str =
        "application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml";
    /// 备注母版:`.../presentationml.notesMaster+xml`(`/ppt/notesMasters/notesMasterN.xml`,TODO-045)。
    ///
    /// 对应 OOXML 中 `<p:notesMaster>` 根元素,被 `presentation.xml`
    /// 的 `<p:notesMasterIdLst>` 引用。
    pub const NOTES_MASTER: &str =
        "application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml";
    /// 幻灯片评论:`.../presentationml.comments+xml`(`/ppt/comments/commentN.xml`)。
    ///
    /// 对应 OOXML 中 `<p:cmLst>` 根元素,命名空间为
    /// `http://schemas.openxmlformats.org/presentationml/2006/main`。
    pub const COMMENTS: &str =
        "application/vnd.openxmlformats-officedocument.presentationml.comments+xml";
    /// 评论作者列表:`.../presentationml.commentAuthors+xml`(`/ppt/commentAuthors.xml`)。
    ///
    /// 全局共享的作者清单,对应 `<p:cmAuthorLst>` 根元素。
    pub const COMMENT_AUTHORS: &str =
        "application/vnd.openxmlformats-officedocument.presentationml.commentAuthors+xml";
}