use mathtex_ir::{FontKey, GlyphId, Length, Point};
pub trait HostBoxes {
fn host_box(&self, request: &HostBoxRequest) -> Option<HostBox>;
fn revision(&self, _token: u32) -> Option<u64> {
None
}
}
impl<T> HostBoxes for &T
where
T: HostBoxes + ?Sized,
{
fn host_box(&self, request: &HostBoxRequest) -> Option<HostBox> {
(**self).host_box(request)
}
fn revision(&self, token: u32) -> Option<u64> {
(**self).revision(token)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct NoHostBoxes;
impl HostBoxes for NoHostBoxes {
fn host_box(&self, _request: &HostBoxRequest) -> Option<HostBox> {
None
}
fn revision(&self, _token: u32) -> Option<u64> {
Some(0)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum MathStyle {
Text,
Script,
ScriptScript,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct HostBoxRequest {
pub token: u32,
pub style: MathStyle,
pub size: Length,
}
impl HostBoxRequest {
#[must_use]
pub fn new(token: u32, style: MathStyle, size: Length) -> Self {
Self { token, style, size }
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct HostBox {
pub width: Length,
pub height: Length,
pub depth: Length,
pub runs: Vec<HostBoxRun>,
pub rules: Vec<HostBoxRule>,
}
impl HostBox {
#[must_use]
pub fn new(width: Length, height: Length, depth: Length) -> Self {
Self {
width,
height,
depth,
runs: Vec::new(),
rules: Vec::new(),
}
}
#[must_use]
pub fn with_run(mut self, run: HostBoxRun) -> Self {
self.runs.push(run);
self
}
#[must_use]
pub fn with_rule(mut self, rule: HostBoxRule) -> Self {
self.rules.push(rule);
self
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct HostBoxRun {
pub font: FontKey,
pub size: Length,
pub glyphs: Vec<HostBoxGlyph>,
}
impl HostBoxRun {
#[must_use]
pub fn new(font: FontKey, size: Length, glyphs: Vec<HostBoxGlyph>) -> Self {
Self { font, size, glyphs }
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct HostBoxGlyph {
pub glyph: GlyphId,
pub origin: Point,
}
impl HostBoxGlyph {
#[must_use]
pub fn new(glyph: GlyphId, origin: Point) -> Self {
Self { glyph, origin }
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct HostBoxRule {
pub origin: Point,
pub width: Length,
pub height: Length,
}
impl HostBoxRule {
#[must_use]
pub fn new(origin: Point, width: Length, height: Length) -> Self {
Self {
origin,
width,
height,
}
}
}