easypdf_core/layout/layout_sink.rs
1//! 布局操作的写入后端接口。
2
3use std::path::Path;
4
5use crate::{Orientation, PageSize, PdfText, Result};
6
7/// 接收中立布局操作的 PDF 写入后端。
8pub trait LayoutSink {
9 /// 新增页面并返回一基页码。
10 ///
11 /// # Errors
12 ///
13 /// 后端无法创建页面时返回错误。
14 fn add_page(&mut self, size: PageSize, orientation: Orientation) -> Result<usize>;
15
16 /// 在指定坐标写入文本。
17 ///
18 /// # Errors
19 ///
20 /// 后端无法写入文本时返回错误。
21 fn write_text(&mut self, text: &PdfText, x: f64, y: f64) -> Result<()>;
22
23 /// 完成文档并保存。
24 ///
25 /// # Errors
26 ///
27 /// 后端无法完成或保存文档时返回错误。
28 fn finish(self, path: &Path) -> Result<()>
29 where
30 Self: Sized;
31}