use printpdf::Pt;
use crate::typography::Glyph;
#[derive(Debug)]
pub struct Item<'a> {
pub width: Pt,
pub content: Content<'a>,
}
#[derive(Debug)]
pub enum Content<'a> {
BoundingBox(Glyph<'a>),
Glue {
stretchability: Pt,
shrinkability: Pt,
},
Penalty {
value: f64,
flagged: bool,
},
}
impl<'a> Item<'a> {
pub fn from_glyph(glyph: Glyph<'a>) -> Item<'a> {
Item {
width: glyph.font.char_width(glyph.glyph, glyph.scale),
content: Content::BoundingBox(glyph),
}
}
pub fn glue(ideal_spacing: Pt, stretchability: Pt, shrinkability: Pt) -> Item<'a> {
Item {
width: ideal_spacing,
content: Content::Glue {
stretchability,
shrinkability,
},
}
}
pub fn penalty(width: Pt, value: f64, flagged: bool) -> Item<'a> {
Item {
width,
content: Content::Penalty { value, flagged },
}
}
}
#[derive(Debug)]
pub struct PositionedItem<'a> {
pub index: usize,
pub line: usize,
pub horizontal_offset: Pt,
pub width: Pt,
pub glyph: Glyph<'a>,
}