use serde::{Deserialize, Serialize};
use super::bbox::BoundingBox;
use super::chunks::{ImageChunk, LineArtChunk, LineChunk, TextChunk};
use super::list::PDFList;
use super::semantic::{
SemanticCaption, SemanticFigure, SemanticFormula, SemanticHeaderOrFooter, SemanticHeading,
SemanticNumberHeading, SemanticParagraph, SemanticPicture, SemanticTable,
};
use super::table::TableBorder;
use super::text::{TextBlock, TextLine};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ContentElement {
TextChunk(TextChunk),
TextLine(TextLine),
TextBlock(TextBlock),
Image(ImageChunk),
Line(LineChunk),
LineArt(LineArtChunk),
TableBorder(TableBorder),
List(PDFList),
Paragraph(SemanticParagraph),
Heading(SemanticHeading),
NumberHeading(SemanticNumberHeading),
Caption(SemanticCaption),
HeaderFooter(SemanticHeaderOrFooter),
Figure(SemanticFigure),
Formula(SemanticFormula),
Picture(SemanticPicture),
Table(SemanticTable),
}
impl ContentElement {
pub fn bbox(&self) -> &BoundingBox {
match self {
Self::TextChunk(e) => &e.bbox,
Self::TextLine(e) => &e.bbox,
Self::TextBlock(e) => &e.bbox,
Self::Image(e) => &e.bbox,
Self::Line(e) => &e.bbox,
Self::LineArt(e) => &e.bbox,
Self::TableBorder(e) => &e.bbox,
Self::List(e) => &e.bbox,
Self::Paragraph(e) => &e.base.bbox,
Self::Heading(e) => &e.base.base.bbox,
Self::NumberHeading(e) => &e.base.base.base.bbox,
Self::Caption(e) => &e.base.bbox,
Self::HeaderFooter(e) => &e.bbox,
Self::Figure(e) => &e.bbox,
Self::Formula(e) => &e.bbox,
Self::Picture(e) => &e.bbox,
Self::Table(e) => &e.bbox,
}
}
pub fn index(&self) -> Option<u32> {
match self {
Self::TextChunk(e) => e.index.map(|i| i as u32),
Self::TextLine(e) => e.index,
Self::TextBlock(e) => e.index,
Self::Image(e) => e.index,
Self::Line(e) => e.index,
Self::LineArt(e) => e.index,
Self::TableBorder(e) => e.index,
Self::List(e) => e.index,
Self::Paragraph(e) => e.base.index,
Self::Heading(e) => e.base.base.index,
Self::NumberHeading(e) => e.base.base.base.index,
Self::Caption(e) => e.base.index,
Self::HeaderFooter(e) => e.index,
Self::Figure(e) => e.index,
Self::Formula(e) => e.index,
Self::Picture(e) => e.index,
Self::Table(e) => e.index,
}
}
pub fn page_number(&self) -> Option<u32> {
self.bbox().page_number
}
pub fn set_index(&mut self, idx: u32) {
match self {
Self::TextChunk(e) => e.index = Some(idx as usize),
Self::TextLine(e) => e.index = Some(idx),
Self::TextBlock(e) => e.index = Some(idx),
Self::Image(e) => e.index = Some(idx),
Self::Line(e) => e.index = Some(idx),
Self::LineArt(e) => e.index = Some(idx),
Self::TableBorder(e) => e.index = Some(idx),
Self::List(e) => e.index = Some(idx),
Self::Paragraph(e) => e.base.index = Some(idx),
Self::Heading(e) => e.base.base.index = Some(idx),
Self::NumberHeading(e) => e.base.base.base.index = Some(idx),
Self::Caption(e) => e.base.index = Some(idx),
Self::HeaderFooter(e) => e.index = Some(idx),
Self::Figure(e) => e.index = Some(idx),
Self::Formula(e) => e.index = Some(idx),
Self::Picture(e) => e.index = Some(idx),
Self::Table(e) => e.index = Some(idx),
}
}
}