use super::fonts::FaceId;
use crate::word::fmt::model::Rgb;
#[derive(Debug, Clone, Default)]
pub struct Page {
pub width: f32,
pub height: f32,
pub items: Vec<Item>,
}
impl Page {
pub fn compact(&mut self) {
self.items.shrink_to_fit();
for item in &mut self.items {
if let Item::Text(run) = item {
run.glyphs.shrink_to_fit();
run.text.shrink_to_fit();
}
}
}
}
#[derive(Debug, Clone)]
pub enum Item {
Text(TextRun),
Rect {
x: f32,
y: f32,
width: f32,
height: f32,
color: Rgb,
},
Line {
x1: f32,
y1: f32,
x2: f32,
y2: f32,
width: f32,
color: Rgb,
dash: Option<f32>,
},
Image {
index: usize,
x: f32,
y: f32,
width: f32,
height: f32,
crop: [f32; 4],
},
Link {
x: f32,
y: f32,
width: f32,
height: f32,
target: String,
},
}
#[derive(Debug, Clone)]
pub struct TextRun {
pub face: FaceId,
pub size: f32,
pub x: f32,
pub y: f32,
pub color: Rgb,
pub glyphs: Vec<Glyph>,
pub text: String,
pub fake_bold: bool,
pub fake_italic: bool,
pub scale: f32,
}
#[derive(Debug, Clone, Copy)]
pub struct Glyph {
pub id: u16,
pub x: f32,
pub advance: f32,
pub dx: f32,
pub dy: f32,
pub text: (u32, u32),
}
impl Glyph {
#[must_use]
pub fn range(&self) -> std::ops::Range<usize> {
self.text.0 as usize..self.text.1 as usize
}
}
#[must_use]
pub fn offset(at: usize) -> u32 {
u32::try_from(at).unwrap_or(u32::MAX)
}
#[derive(Debug, Clone)]
pub struct Destination {
pub name: String,
pub page: usize,
pub y: f32,
}