#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Point {
pub x: f64,
pub y: f64,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Rect {
pub x: f64,
pub y: f64,
pub width: f64,
pub height: f64,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Color {
pub r: f64,
pub g: f64,
pub b: f64,
pub a: f64,
}
impl Color {
pub const BLACK: Color = Color {
r: 0.0,
g: 0.0,
b: 0.0,
a: 1.0,
};
pub const WHITE: Color = Color {
r: 1.0,
g: 1.0,
b: 1.0,
a: 1.0,
};
pub fn from_hex(hex: &str) -> Self {
let hex = hex.trim_start_matches('#');
if hex.len() >= 6 {
let r = u8::from_str_radix(&hex[0..2], 16).unwrap_or(0) as f64 / 255.0;
let g = u8::from_str_radix(&hex[2..4], 16).unwrap_or(0) as f64 / 255.0;
let b = u8::from_str_radix(&hex[4..6], 16).unwrap_or(0) as f64 / 255.0;
Color { r, g, b, a: 1.0 }
} else {
Color::BLACK
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FontId(pub u32);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FieldKind {
Page,
NumPages,
}
#[derive(Debug, Clone)]
pub struct GlyphRun {
pub origin: Point,
pub font_id: FontId,
pub font_size: f64,
pub glyph_ids: Vec<u16>,
pub advances: Vec<f64>,
pub text: String,
pub color: Color,
pub bold: bool,
pub italic: bool,
pub field_kind: Option<FieldKind>,
pub footnote_id: Option<i32>,
}
#[derive(Debug, Clone)]
pub enum PositionedElement {
Text(GlyphRun),
Line {
start: Point,
end: Point,
width: f64,
color: Color,
dash_pattern: Option<(f64, f64)>,
},
FilledRect { rect: Rect, color: Color },
Image {
rect: Rect,
data: Vec<u8>,
content_type: String,
embed_id: Option<String>,
},
LinkAnnotation { rect: Rect, url: String },
}
#[derive(Debug, Clone)]
pub struct PageFrame {
pub page_number: usize,
pub width: f64,
pub height: f64,
pub elements: Vec<PositionedElement>,
}
#[derive(Debug, Clone)]
pub struct FontData {
pub id: FontId,
pub family: String,
pub data: Vec<u8>,
pub face_index: u32,
pub bold: bool,
pub italic: bool,
}
#[derive(Debug, Clone, Default)]
pub struct DocumentMetadata {
pub title: Option<String>,
pub author: Option<String>,
pub subject: Option<String>,
pub keywords: Option<String>,
pub creator: Option<String>,
}
#[derive(Debug, Clone)]
pub struct OutlineEntry {
pub title: String,
pub level: u32,
pub page_index: usize,
pub y_position: f64,
}
#[derive(Debug, Clone)]
pub struct LayoutResult {
pub pages: Vec<PageFrame>,
pub fonts: Vec<FontData>,
pub metadata: Option<DocumentMetadata>,
pub outlines: Vec<OutlineEntry>,
}