#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Span {
pub text: String,
pub bold: bool,
pub italic: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Fragment {
pub top: i32,
pub left: i32,
pub width: i32,
pub height: i32,
pub font: u32,
pub spans: Vec<Span>,
}
impl Fragment {
pub fn right(&self) -> i32 {
self.left + self.width
}
pub fn char_count(&self) -> usize {
self.spans
.iter()
.map(|span| span.text.chars().filter(|ch| !ch.is_whitespace()).count())
.sum()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Line {
pub top: i32,
pub left: i32,
pub right: i32,
pub height: i32,
pub font_size: u32,
pub spans: Vec<Span>,
}
impl Line {
pub fn width(&self) -> i32 {
self.right - self.left
}
pub fn text(&self) -> String {
self.spans
.iter()
.map(|span| span.text.as_str())
.collect::<String>()
}
pub fn char_count(&self) -> usize {
self.spans
.iter()
.map(|span| span.text.chars().filter(|ch| !ch.is_whitespace()).count())
.sum()
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Page {
pub number: u32,
pub width: i32,
pub height: i32,
pub fragments: Vec<Fragment>,
pub font_sizes: std::collections::HashMap<u32, u32>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ColumnMode {
#[default]
Auto,
Single,
Two,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DocBlock {
Heading { level: u8, spans: Vec<Span> },
Paragraph { spans: Vec<Span> },
}
impl DocBlock {
pub fn spans(&self) -> &[Span] {
match self {
DocBlock::Heading { spans, .. } => spans,
DocBlock::Paragraph { spans } => spans,
}
}
pub fn text(&self) -> String {
self.spans()
.iter()
.map(|span| span.text.as_str())
.collect::<String>()
}
pub fn char_count(&self) -> usize {
self.spans()
.iter()
.map(|span| span.text.chars().filter(|ch| !ch.is_whitespace()).count())
.sum()
}
}