Skip to main content

Module render

Module render 

Source
Expand description

OFD → 图片渲染(光栅化)。

crate::OfdReader 之上提供将版式页面渲染为位图的能力:

  • 以毫米为单位的页面物理区域,按给定 DPI 换算为像素画布;
  • 依模板页(背景/前景)与图层类型(Background/Body/Foreground)的叠放 次序,逐个绘制文字、图形与图像对象;
  • 通过 image 编码为 PNG / JPEG / BMP / TIFF / GIF / WebP 等常见格式, 格式由参数指定。

坐标与变换遵循规范 8.5:页面坐标系原点位于物理区域左上角,y 轴向下; 每个图元对象的内部坐标先经其变换矩阵 CTM,再平移到边界 Boundary 左上角,得到页面坐标,最后按 DPI 缩放到设备像素。

§示例

use ofd_core::{OfdReader, render::RenderOptions};

let mut reader = OfdReader::open("sample.ofd")?;
let body = reader.ofd().doc_bodies[0].clone();
let doc = reader.load_document(&body)?;

// 将首页以 200 DPI 渲染并保存为 PNG(格式由扩展名推断)。
let opts = RenderOptions::with_dpi(200.0);
reader.render_page_to_file(&doc, 0, &opts, "page0.png")?;

Structs§

RenderOptions
渲染参数。

Enums§

ImageFormat
重新导出 image::ImageFormat,便于调用方指定输出格式而无需直接依赖 image。 An enumeration of supported image formats. Not all formats support both encoding and decoding.

Functions§

image_format_from_ext
由扩展名/格式名(不含点,大小写不敏感)映射到 ImageFormat