Skip to main content

OfdReader

Struct OfdReader 

Source
pub struct OfdReader<R> { /* private fields */ }
Expand description

OFD 文档的高层读取器。

打开时即解析主入口 OfdOFD.xml),随后可按需装载各版式文档的根节点、 页对象、模板页与资源;装载过程自动完成 StLoc 的相对/绝对路径解析。

Implementations§

Source§

impl<R: Read + Seek> OfdReader<R>

Source

pub fn render_page( &mut self, doc: &LoadedDocument, page_index: usize, options: &RenderOptions, ) -> Result<Pixmap>

将文档第 page_index 页渲染为像素图(tiny_skia::Pixmap)。

page_index 为页树中的页序号(从 0 起)。

Source

pub fn render_page_to_image( &mut self, doc: &LoadedDocument, page_index: usize, options: &RenderOptions, ) -> Result<RgbaImage>

将指定页渲染为 image::RgbaImage

Source

pub fn render_page_to_bytes( &mut self, doc: &LoadedDocument, page_index: usize, options: &RenderOptions, format: ImageFormat, ) -> Result<Vec<u8>>

将指定页渲染并编码为给定格式的图片字节。

Source

pub fn render_page_to_file<P: AsRef<Path>>( &mut self, doc: &LoadedDocument, page_index: usize, options: &RenderOptions, path: P, ) -> Result<()>

将指定页渲染并写入文件,图片格式由路径扩展名推断。

支持的扩展名:pngjpg/jpegbmptif/tiffgifwebp

Source§

impl<R: Read + Seek> OfdReader<R>

Source

pub fn load_signatures(&mut self) -> Result<Vec<LoadedSignature>>

装载文档登记的全部签名(Signatures.xml 及其引用的各 Signature.xml)。

遍历所有 DocBody,对声明了 Signatures 的文档解析其签名列表与每份签名 描述。返回的 LoadedSignature 携带在包内的解析路径,供完整性校验定位。

Source

pub fn verify_signature(&mut self, loaded: &LoadedSignature) -> SignatureReport

校验单个签名的完整性:逐个重算被保护文件的摘要并与 CheckValue 比对。

Source

pub fn verify_signatures(&mut self) -> Result<Vec<SignatureReport>>

校验文档全部签名的完整性,返回逐个签名的报告。

Source§

impl OfdReader<File>

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

从文件系统路径打开一个 OFD 文档。

Source§

impl<R: Read + Seek> OfdReader<R>

Source

pub fn new(package: OfdPackage<R>) -> Result<Self>

基于已打开的 OfdPackage 创建读取器,并解析主入口 OFD.xml

Source

pub fn ofd(&self) -> &Ofd

主入口数据模型(OFD.xml)。

Source

pub fn package_mut(&mut self) -> &mut OfdPackage<R>

底层容器的可变引用,便于读取本库未直接建模的部件。

Source

pub fn load_document(&mut self, body: &DocBody) -> Result<LoadedDocument>

装载某个版式文档的根节点(Document.xml)。

返回的 LoadedDocument 携带文档所在目录,供后续解析页、资源等 相对路径使用。

Source

pub fn load_page( &mut self, doc: &LoadedDocument, page: &PageRef, ) -> Result<PageObject>

装载页树中某一页的页对象(Content.xml)。

Source

pub fn load_template( &mut self, doc: &LoadedDocument, template: &CtTemplatePage, ) -> Result<PageObject>

装载某个模板页的内容(结构与普通页相同)。

Source

pub fn load_resource( &mut self, doc: &LoadedDocument, loc: &StLoc, ) -> Result<Res>

装载文档的一个资源文件(公共资源或文档资源)。

Auto Trait Implementations§

§

impl<R> Freeze for OfdReader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for OfdReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for OfdReader<R>
where R: Send,

§

impl<R> Sync for OfdReader<R>
where R: Sync,

§

impl<R> Unpin for OfdReader<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for OfdReader<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for OfdReader<R>
where R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.