use std::fmt;
use crate::error::Result;
use crate::model::Rect;
#[derive(Debug, Clone, Default)]
pub struct RawTextItem {
pub text: String,
pub bbox: Option<Rect>,
}
#[derive(Debug, Clone, Default)]
pub struct RawImage {
pub data: Vec<u8>,
pub bbox: Option<Rect>,
pub ext: String,
pub px: Option<(u32, u32)>,
pub ocr_text: Option<String>,
}
#[derive(Debug, Clone, Default)]
pub struct RawPage {
pub name: Option<String>,
pub items: Vec<RawTextItem>,
pub images: Vec<RawImage>,
pub width: Option<f32>,
pub height: Option<f32>,
pub rotation: Option<i32>,
pub tables: Vec<Vec<Vec<String>>>,
}
#[derive(Debug, Clone, Default)]
pub struct RawDoc {
pub pages: Vec<RawPage>,
pub meta: std::collections::HashMap<String, String>,
pub needs_ocr: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BackendKind {
Bundled,
External,
Composite,
}
impl BackendKind {
pub fn as_str(&self) -> &'static str {
match self {
BackendKind::Bundled => "bundled",
BackendKind::External => "external",
BackendKind::Composite => "composite",
}
}
}
impl fmt::Display for BackendKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
pub trait ParseCapability: Send + Sync {
fn id(&self) -> &str;
fn formats(&self) -> &[&str];
fn kind(&self) -> BackendKind {
BackendKind::Bundled
}
fn is_available(&self) -> bool {
true
}
fn parse(&self, path: &str) -> Result<RawDoc>;
}
pub trait ProcessCapability: Send + Sync {
fn id(&self) -> &str;
fn is_available(&self) -> bool {
true
}
fn should_apply(&self, _raw: &RawDoc) -> bool {
true
}
fn process(&self, raw: &mut RawDoc) -> Result<()>;
}
pub trait FormatPlugin: Send + Sync {
fn id(&self) -> &str;
fn formats(&self) -> &[&str];
fn default_parse_chain(&self) -> Vec<&'static str>;
fn default_process_chain(&self) -> Vec<&'static str>;
fn assemble(&self, raw: &RawDoc) -> crate::model::Document;
}