use crate::error::PdfResult;
#[derive(Debug, Clone)]
pub struct OcrWord {
pub text: String,
pub x: u32,
pub y: u32,
pub width: u32,
pub height: u32,
pub confidence: f32,
}
#[derive(Debug, Clone)]
pub struct OcrResult {
pub words: Vec<OcrWord>,
pub image_width: u32,
pub image_height: u32,
}
#[derive(Debug, Clone)]
pub struct OcrImage {
pub data: Vec<u8>,
pub width: u32,
pub height: u32,
}
pub trait OcrEngine {
fn recognize(&self, image: &OcrImage) -> PdfResult<OcrResult>;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ocr_word_fields() {
let word = OcrWord {
text: "Hello".to_string(),
x: 100,
y: 200,
width: 80,
height: 20,
confidence: 0.95,
};
assert_eq!(word.text, "Hello");
assert!(word.confidence > 0.9);
}
#[test]
fn ocr_result_default() {
let result = OcrResult {
words: Vec::new(),
image_width: 612,
image_height: 792,
};
assert!(result.words.is_empty());
}
#[test]
fn ocr_image_construction() {
let img = OcrImage {
data: vec![128; 100],
width: 10,
height: 10,
};
assert_eq!(img.data.len(), 100);
}
}