1use std::fmt;
5
6use crate::error::Result;
7use crate::model::Rect;
8
9#[derive(Debug, Clone, Default)]
11pub struct RawTextItem {
12 pub text: String,
13 pub bbox: Option<Rect>,
14}
15
16#[derive(Debug, Clone, Default)]
18pub struct RawImage {
19 pub data: Vec<u8>,
20 pub bbox: Option<Rect>,
21 pub ext: String,
22 pub px: Option<(u32, u32)>,
24 pub ocr_text: Option<String>,
26}
27
28#[derive(Debug, Clone, Default)]
29pub struct RawPage {
30 pub name: Option<String>,
31 pub items: Vec<RawTextItem>,
32 pub images: Vec<RawImage>,
33 pub width: Option<f32>,
34 pub height: Option<f32>,
35 pub rotation: Option<i32>,
36 pub tables: Vec<Vec<Vec<String>>>,
38}
39
40#[derive(Debug, Clone, Default)]
42pub struct RawDoc {
43 pub pages: Vec<RawPage>,
44 pub meta: std::collections::HashMap<String, String>,
45 pub needs_ocr: bool,
46}
47
48#[derive(Debug, Clone, Copy, PartialEq, Eq)]
50pub enum BackendKind {
51 Bundled,
52 External,
53 Composite,
54}
55
56impl BackendKind {
57 pub fn as_str(&self) -> &'static str {
58 match self {
59 BackendKind::Bundled => "bundled",
60 BackendKind::External => "external",
61 BackendKind::Composite => "composite",
62 }
63 }
64}
65
66impl fmt::Display for BackendKind {
67 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
68 f.write_str(self.as_str())
69 }
70}
71
72pub trait ParseCapability: Send + Sync {
74 fn id(&self) -> &str;
75 fn formats(&self) -> &[&str];
76 fn kind(&self) -> BackendKind {
77 BackendKind::Bundled
78 }
79 fn is_available(&self) -> bool {
80 true
81 }
82 fn parse(&self, path: &str) -> Result<RawDoc>;
83}
84
85pub trait ProcessCapability: Send + Sync {
87 fn id(&self) -> &str;
88 fn is_available(&self) -> bool {
89 true
90 }
91 fn should_apply(&self, _raw: &RawDoc) -> bool {
92 true
93 }
94 fn process(&self, raw: &mut RawDoc) -> Result<()>;
95}
96
97pub trait FormatPlugin: Send + Sync {
99 fn id(&self) -> &str;
100 fn formats(&self) -> &[&str];
101 fn default_parse_chain(&self) -> Vec<&'static str>;
102 fn default_process_chain(&self) -> Vec<&'static str>;
103 fn assemble(&self, raw: &RawDoc) -> crate::model::Document;
104}