use ratex_types::color::Color;
use ratex_types::path_command::PathCommand;
#[derive(Debug, Clone)]
pub struct LayoutBox {
pub width: f64,
pub height: f64,
pub depth: f64,
pub content: BoxContent,
pub color: Color,
}
#[derive(Debug, Clone)]
pub enum BoxContent {
HBox(Vec<LayoutBox>),
VBox(Vec<VBoxChild>),
Glyph {
font_id: ratex_font::FontId,
char_code: u32,
},
Rule {
thickness: f64,
raise: f64,
},
Kern,
Fraction {
numer: Box<LayoutBox>,
denom: Box<LayoutBox>,
numer_shift: f64,
denom_shift: f64,
bar_thickness: f64,
numer_scale: f64,
denom_scale: f64,
},
SupSub {
base: Box<LayoutBox>,
sup: Option<Box<LayoutBox>>,
sub: Option<Box<LayoutBox>>,
sup_shift: f64,
sub_shift: f64,
sup_scale: f64,
sub_scale: f64,
center_scripts: bool,
italic_correction: f64,
sub_h_kern: f64,
},
Radical {
body: Box<LayoutBox>,
index: Option<Box<LayoutBox>>,
index_offset: f64,
index_scale: f64,
rule_thickness: f64,
inner_height: f64,
},
OpLimits {
base: Box<LayoutBox>,
sup: Option<Box<LayoutBox>>,
sub: Option<Box<LayoutBox>>,
base_shift: f64,
sup_kern: f64,
sub_kern: f64,
slant: f64,
sup_scale: f64,
sub_scale: f64,
},
Accent {
base: Box<LayoutBox>,
accent: Box<LayoutBox>,
clearance: f64,
skew: f64,
is_below: bool,
under_gap_em: f64,
},
LeftRight {
left: Box<LayoutBox>,
right: Box<LayoutBox>,
inner: Box<LayoutBox>,
},
Array {
cells: Vec<Vec<LayoutBox>>,
col_widths: Vec<f64>,
col_aligns: Vec<u8>,
row_heights: Vec<f64>,
row_depths: Vec<f64>,
col_gap: f64,
offset: f64,
content_x_offset: f64,
col_separators: Vec<Option<bool>>,
hlines_before_row: Vec<Vec<bool>>,
rule_thickness: f64,
double_rule_sep: f64,
},
SvgPath {
commands: Vec<PathCommand>,
fill: bool,
},
Framed {
body: Box<LayoutBox>,
padding: f64,
border_thickness: f64,
has_border: bool,
bg_color: Option<Color>,
border_color: Color,
},
RaiseBox {
body: Box<LayoutBox>,
shift: f64,
},
Scaled {
body: Box<LayoutBox>,
child_scale: f64,
},
Angl {
path_commands: Vec<PathCommand>,
body: Box<LayoutBox>,
},
Overline {
body: Box<LayoutBox>,
rule_thickness: f64,
},
Underline {
body: Box<LayoutBox>,
rule_thickness: f64,
},
Empty,
}
#[derive(Debug, Clone)]
pub struct VBoxChild {
pub kind: VBoxChildKind,
pub shift: f64,
}
#[derive(Debug, Clone)]
pub enum VBoxChildKind {
Box(Box<LayoutBox>),
Kern(f64),
}
impl LayoutBox {
pub fn new_empty() -> Self {
Self {
width: 0.0,
height: 0.0,
depth: 0.0,
content: BoxContent::Empty,
color: Color::BLACK,
}
}
pub fn new_kern(width: f64) -> Self {
Self {
width,
height: 0.0,
depth: 0.0,
content: BoxContent::Kern,
color: Color::BLACK,
}
}
pub fn new_rule(width: f64, height: f64, depth: f64, thickness: f64, raise: f64) -> Self {
Self {
width,
height,
depth,
content: BoxContent::Rule { thickness, raise },
color: Color::BLACK,
}
}
pub fn total_height(&self) -> f64 {
self.height + self.depth
}
pub fn with_color(mut self, color: Color) -> Self {
self.color = color;
self
}
pub fn with_adjusted_delim(mut self, height: f64, depth: f64) -> Self {
self.height = height;
self.depth = depth;
self
}
}