use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MarkupData {
#[serde(skip_serializing_if = "Option::is_none")]
pub highlight: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub underline: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub squiggly: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub strikeout: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TextItem {
pub str: String,
pub x: f64,
pub y: f64,
pub width: f64,
pub height: f64,
pub w: f64,
pub h: f64,
#[serde(skip_serializing_if = "Option::is_none")]
pub font_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub font_size: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rx: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ry: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub markup: Option<MarkupData>,
#[serde(skip_serializing_if = "Option::is_none")]
pub vgap: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_placeholder: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub confidence: Option<f64>,
}
impl TextItem {
pub fn new(str: impl Into<String>, x: f64, y: f64, width: f64, height: f64) -> Self {
let s = str.into();
Self {
str: s,
x,
y,
width,
height,
w: width,
h: height,
font_name: None,
font_size: None,
r: None,
rx: None,
ry: None,
markup: None,
vgap: None,
is_placeholder: None,
confidence: None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Snap {
Left,
Right,
Center,
}
#[derive(Debug, Clone)]
pub struct ProjectionTextBox {
pub str: String,
pub x: f64,
pub y: f64,
pub w: f64,
pub h: f64,
pub rx: Option<f64>,
pub ry: Option<f64>,
pub r: Option<i32>,
pub str_length: usize,
pub markup: Option<MarkupData>,
pub page_bbox: Option<Coordinates>,
pub vgap: bool,
pub is_placeholder: bool,
pub from_ocr: bool,
pub snap: Option<Snap>,
pub left_anchor: Option<String>,
pub right_anchor: Option<String>,
pub center_anchor: Option<String>,
pub is_dup: bool,
pub rendered: bool,
pub is_margin_line_number: bool,
pub should_space: Option<f64>,
pub force_unsnapped: bool,
pub rotated: bool,
pub d: Option<f64>,
pub font_name: Option<String>,
pub font_size: Option<f64>,
pub confidence: Option<f64>,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Coordinates {
pub x: f64,
pub y: f64,
pub w: f64,
pub h: f64,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BoundingBox {
pub x1: f64,
pub y1: f64,
pub x2: f64,
pub y2: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OcrData {
pub x: f64,
pub y: f64,
pub w: f64,
pub h: f64,
pub confidence: f64,
pub text: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ParsedPage {
pub page_num: u32,
pub width: f64,
pub height: f64,
pub text: String,
pub text_items: Vec<TextItem>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bounding_boxes: Option<Vec<BoundingBox>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct JsonTextItem {
pub text: String,
pub x: f64,
pub y: f64,
pub width: f64,
pub height: f64,
#[serde(skip_serializing_if = "Option::is_none")]
pub font_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub font_size: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub confidence: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct JsonPage {
pub page: u32,
pub width: f64,
pub height: f64,
pub text: String,
pub text_items: Vec<JsonTextItem>,
pub bounding_boxes: Vec<BoundingBox>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParseResultJson {
pub pages: Vec<JsonPage>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParseResult {
pub pages: Vec<ParsedPage>,
pub text: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub json: Option<ParseResultJson>,
}
#[derive(Debug, Clone)]
pub struct Image {
pub x: f64,
pub y: f64,
pub width: f64,
pub height: f64,
pub data: Option<Vec<u8>>,
pub scale_factor: Option<f64>,
pub original_orientation_angle: Option<i32>,
pub image_type: Option<String>,
}
#[derive(Debug, Clone)]
pub struct ScreenshotResult {
pub page_num: u32,
pub width: u32,
pub height: u32,
pub image_buffer: Vec<u8>,
pub image_path: Option<std::path::PathBuf>,
}