mathtex_engine/
host_box.rs1use mathtex_ir::{FontKey, GlyphId, Length, Point};
2
3pub trait HostBoxes {
5 fn host_box(&self, request: &HostBoxRequest) -> Option<HostBox>;
7
8 fn revision(&self, _token: u32) -> Option<u64> {
10 None
11 }
12}
13
14impl<T> HostBoxes for &T
15where
16 T: HostBoxes + ?Sized,
17{
18 fn host_box(&self, request: &HostBoxRequest) -> Option<HostBox> {
19 (**self).host_box(request)
20 }
21
22 fn revision(&self, token: u32) -> Option<u64> {
23 (**self).revision(token)
24 }
25}
26
27#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
29pub struct NoHostBoxes;
30
31impl HostBoxes for NoHostBoxes {
32 fn host_box(&self, _request: &HostBoxRequest) -> Option<HostBox> {
33 None
34 }
35
36 fn revision(&self, _token: u32) -> Option<u64> {
37 Some(0)
38 }
39}
40
41#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
43#[non_exhaustive]
44pub enum MathStyle {
45 Text,
47 Script,
49 ScriptScript,
51}
52
53#[derive(Clone, Copy, Debug, PartialEq, Eq)]
55#[non_exhaustive]
56pub struct HostBoxRequest {
57 pub token: u32,
59 pub style: MathStyle,
61 pub size: Length,
63}
64
65impl HostBoxRequest {
66 #[must_use]
68 pub fn new(token: u32, style: MathStyle, size: Length) -> Self {
69 Self { token, style, size }
70 }
71}
72
73#[derive(Clone, Debug, PartialEq, Eq)]
75#[non_exhaustive]
76pub struct HostBox {
77 pub width: Length,
79 pub height: Length,
81 pub depth: Length,
83 pub runs: Vec<HostBoxRun>,
85 pub rules: Vec<HostBoxRule>,
87}
88
89impl HostBox {
90 #[must_use]
92 pub fn new(width: Length, height: Length, depth: Length) -> Self {
93 Self {
94 width,
95 height,
96 depth,
97 runs: Vec::new(),
98 rules: Vec::new(),
99 }
100 }
101
102 #[must_use]
104 pub fn with_run(mut self, run: HostBoxRun) -> Self {
105 self.runs.push(run);
106 self
107 }
108
109 #[must_use]
111 pub fn with_rule(mut self, rule: HostBoxRule) -> Self {
112 self.rules.push(rule);
113 self
114 }
115}
116
117#[derive(Clone, Debug, PartialEq, Eq)]
119#[non_exhaustive]
120pub struct HostBoxRun {
121 pub font: FontKey,
123 pub size: Length,
125 pub glyphs: Vec<HostBoxGlyph>,
127}
128
129impl HostBoxRun {
130 #[must_use]
132 pub fn new(font: FontKey, size: Length, glyphs: Vec<HostBoxGlyph>) -> Self {
133 Self { font, size, glyphs }
134 }
135}
136
137#[derive(Clone, Copy, Debug, PartialEq, Eq)]
139#[non_exhaustive]
140pub struct HostBoxGlyph {
141 pub glyph: GlyphId,
143 pub origin: Point,
145}
146
147impl HostBoxGlyph {
148 #[must_use]
150 pub fn new(glyph: GlyphId, origin: Point) -> Self {
151 Self { glyph, origin }
152 }
153}
154
155#[derive(Clone, Copy, Debug, PartialEq, Eq)]
157#[non_exhaustive]
158pub struct HostBoxRule {
159 pub origin: Point,
161 pub width: Length,
163 pub height: Length,
165}
166
167impl HostBoxRule {
168 #[must_use]
170 pub fn new(origin: Point, width: Length, height: Length) -> Self {
171 Self {
172 origin,
173 width,
174 height,
175 }
176 }
177}