# ofd_rust **Repository Path**: bill_law6/ofd_rust ## Basic Information - **Project Name**: ofd_rust - **Description**: Rust语言版OFD文档读写工具,使用MiniMax按照ofdrw项目重写 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-26 - **Last Updated**: 2026-05-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # OFD Rust ![License](https://img.shields.io/badge/license-Apache--2.0-blue) ![Rust](https://img.shields.io/badge/rust-1.92+-orange) OFD Reader & Writer 的 Rust 实现版本,参考《GB/T 33190-2016 电子文件存储与交换格式版式文档》标准。 ## 项目介绍 本项目是对 [ofdrw/ofdrw](https://github.com/ofdrw/ofdrw) Java 项目的 Rust 重写版本, 旨在提供高性能、内存安全的 OFD 文档处理能力。 ## 功能特性 - **ofd-core**: OFD 核心 API,包括基础数据类型、XML 元素、基本结构 - **ofd-pkg**: OFD 包管理,支持虚拟文件系统和资源组织 - **ofd-reader**: OFD 文档解析和内容提取 - **ofd-layout**: OFD 文档布局和生成 - **ofd-converter**: OFD 文档转换(支持 PDF、图像、HTML、SVG) - **ofd-graphics2d**: 2D 绘图支持,兼容 Java Graphics2D API - **ofd-font**: 字体管理和字形处理 - **ofd-gm**: 国密算法支持(SM2/SM3/SM4) - **ofd-sign**: 数字签名和电子签章 - **ofd-crypto**: 文档加密和完整性保护 - **ofd-tool**: OFD 工具集(水印、合并、分割、优化) ## OFD 浏览器 项目当前提供图形浏览器: - `gpui-viewer`:桌面图形浏览器,支持缩略图、翻页、缩放、双页预览、文本摘要和 SVG 源码预览 ### 启动桌面浏览器 ```bash cargo run --bin ofd_browser --features gpui-viewer -- demo.ofd ``` 也可以运行示例入口: ```bash cargo run --example gpui_viewer --features gpui-viewer -- demo.ofd ``` ### 浏览器能力 - 左侧页面列表和缩略图导航 - 首页、末页、上一页、下一页、页码跳转 - 适宽、适高、实际尺寸三种预览模式 - 单页 / 双页阅读布局切换 - 当前页文本提取结果和文档摘要信息展示 - 当前页 SVG 预览源码查看 ## OFD 编辑能力 项目当前的编辑类能力主要由 `ofd-tool` 提供: - 页面删除:`OFDPageDeleter` - 文档合并、分割、压缩、优化 - 附件导入、导出和列表管理 - 文本 / 图像水印添加 - 文档结构、页面信息和资源信息提取 当前仓库已补充浏览与编辑回归验证,覆盖“生成 OFD -> 浏览 -> 删除页面 -> 重新浏览 -> 导出 JSON 结构”的基本工作流。 ## 快速开始 ### 环境要求 - Rust 1.92 或更高版本 - Cargo ### 安装 ```bash # 克隆项目 git clone https://github.com/yourusername/ofd_rust.git cd ofd_rust # 构建项目 cargo build ``` ### 使用示例 #### 创建 OFD 文档 ```rust use ofd_layout::OFDDoc; use std::path::Path; // 创建新文档 let doc = OFDDoc::new(Path::new("output.ofd")).unwrap(); // 添加页面 doc.add_page(); // 保存文档 doc.save(); ``` #### 读取 OFD 文档 ```rust use ofd_reader::OFDReader; use std::path::Path; // 打开文档 let reader = OFDReader::new(Path::new("input.ofd")).unwrap(); // 获取页面数量 let page_count = reader.page_count(); // 读取第一页内容 let page = reader.get_page(0); ``` ## 项目结构 ``` ofd_rust/ ├── Cargo.toml # 工作空间配置 ├── README.md # 项目说明 ├── CLAUDE.md # 开发指南 ├── crates/ │ ├── core/ # 核心模块 │ │ ├── src/ │ │ │ ├── basic_type/ # 基础类型 (ST_ID, ST_Loc, ST_Box) │ │ │ ├── element/ # XML 元素 │ │ │ ├── basic_structure/ # 文档基本结构 │ │ │ ├── signatures/ # 签名结构 │ │ │ ├── page_description/ # 页面描述 │ │ │ ├── graph/ # 图形对象 │ │ │ ├── text/ # 文本处理 │ │ │ └── lib.rs │ │ └── Cargo.toml │ ├── pkg/ # 包管理模块 │ │ ├── src/ │ │ │ ├── container/ # 虚拟容器 │ │ │ ├── iterator/ # 迭代器 │ │ │ └── lib.rs │ │ └── Cargo.toml │ ├── reader/ # 文档解析模块 │ │ ├── src/ │ │ │ ├── lib.rs │ │ │ └── validate.rs │ │ └── Cargo.toml │ ├── layout/ # 布局引擎模块 │ │ ├── src/ │ │ │ ├── lib.rs │ │ │ └── ... │ │ └── Cargo.toml │ ├── converter/ # 文档转换模块 │ │ ├── src/ │ │ │ ├── lib.rs │ │ │ ├── export.rs # 导出器 │ │ │ ├── image.rs # 图像 │ │ │ ├── font.rs # 字体 │ │ │ ├── maker.rs # 生成器 │ │ │ └── pubsignature.rs # 公钥签名 │ │ └── Cargo.toml │ ├── graphics2d/ # 2D绘图模块 │ │ ├── src/ │ │ │ ├── lib.rs │ │ │ ├── path.rs │ │ │ └── extended.rs │ │ └── Cargo.toml │ ├── font/ # 字体管理模块 │ │ ├── src/ │ │ │ └── lib.rs │ │ └── Cargo.toml │ ├── gm/ # 国密算法模块 │ │ ├── src/ │ │ │ ├── lib.rs │ │ │ ├── sm2/ # SM2算法 │ │ │ ├── sm3/ # SM3摘要 │ │ │ ├── sm4/ # SM4加密 │ │ │ ├── ses/ # 电子印章 │ │ │ └── ... │ │ └── Cargo.toml │ ├── sign/ # 签名验证模块 │ │ ├── src/ │ │ │ ├── lib.rs │ │ │ └── signer.rs │ │ └── Cargo.toml │ ├── crypto/ # 加密模块 │ │ ├── src/ │ │ │ ├── lib.rs │ │ │ ├── encryptor.rs │ │ │ └── integrity.rs │ │ └── Cargo.toml │ └── tool/ # 工具模块 │ ├── src/ │ │ ├── lib.rs │ │ ├── convert.rs │ │ ├── delete.rs │ │ ├── watermark.rs │ │ ├── util.rs │ │ ├── merge/ # 合并工具 │ │ ├── optimize/ # 优化工具 │ │ └── split/ # 分割工具 │ └── Cargo.toml └── src/ └── main.rs # 主程序入口 ``` ## 核心类型 ### 基础类型 - `ST_ID`: 对象标识,无符号整数,应在文档内唯一 - `ST_Loc`: 路径位置,支持绝对路径和相对路径 - `ST_Box`: 矩形区域,格式: x y width height ### 核心结构 - `Document`: 文档根节点 - `Page`: 页面对象 - `Res`: 资源索引 - `CT_PageArea`: 页面区域 ## 开发指南 ### 添加新依赖 在对应 crate 的 `Cargo.toml` 中添加依赖。 ### 运行测试 ```bash # 运行所有测试 cargo test # 运行指定 crate 的测试 cargo test -p ofd-core cargo test -p ofd-pkg ``` ### 代码规范 - 遵循 Rust 官方代码规范 - 为所有公共 API 添加文档注释 - 使用 TDD 方式开发新功能 ## 参考标准 - [GB/T 33190-2016 电子文件存储与交换格式版式文档](https://www国家标准信息公共服务平台.com/gb/detail/detail.aspx?d=20160914-3393984) ## 许可证 本项目采用 Apache License 2.0 许可证。 ## 贡献 欢迎提交 Issue 和 Pull Request。