easypdf_markdown/render/config.rs
1//! 渲染配置类型。
2
3/// PDF 页面渲染配置。
4///
5/// 控制 DPI、输出格式、背景色和可选的尺寸约束。
6/// 使用 [`RenderConfig::default`] 获取合理默认值
7///(150 DPI、PNG、白色背景、无尺寸限制)。
8///
9/// # Examples
10///
11/// ```
12/// use easypdf_markdown::render::{RenderConfig, ImageFormat, Background};
13///
14/// let config = RenderConfig {
15/// dpi: 300,
16/// format: ImageFormat::Png,
17/// background: Background::White,
18/// max_width: Some(2048),
19/// max_height: None,
20/// };
21/// assert_eq!(config.dpi, 300);
22/// ```
23#[derive(Debug, Clone)]
24pub struct RenderConfig {
25 /// 渲染分辨率(每英寸点数)。默认值:150。
26 pub dpi: u32,
27 /// 输出图像格式。默认值:[`ImageFormat::Png`]。
28 pub format: ImageFormat,
29 /// 页面背景色。默认值:[`Background::White`]。
30 pub background: Background,
31 /// 最大输出宽度(像素)。`None` 表示无限制。
32 pub max_width: Option<u32>,
33 /// 最大输出高度(像素)。`None` 表示无限制。
34 pub max_height: Option<u32>,
35}
36
37impl Default for RenderConfig {
38 fn default() -> Self {
39 Self {
40 dpi: 150,
41 format: ImageFormat::Png,
42 background: Background::White,
43 max_width: None,
44 max_height: None,
45 }
46 }
47}
48
49/// 渲染页面的输出图像格式。
50#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
51#[non_exhaustive]
52pub enum ImageFormat {
53 /// 便携式网络图形(无损)。
54 Png,
55 /// JPEG(有损,文件更小)。
56 Jpeg,
57}
58
59/// 渲染页面的背景色。
60#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
61#[non_exhaustive]
62pub enum Background {
63 /// 纯白背景。
64 White,
65 /// 透明背景(需要 PNG 输出)。
66 Transparent,
67}