pub(super) struct InlineTableTextMetrics {
advances: Vec<f64>,
languages: Vec<usize>,
}
impl InlineTableTextMetrics {
pub(super) fn new(
chars: &[char],
segments: &[(usize, usize)],
mut advance: impl FnMut(usize, usize) -> f64,
) -> Self {
let mut result = Self {
advances: vec![0.0; chars.len()],
languages: vec![0; chars.len()],
};
for &(start, end) in segments {
let mut language = 0;
for (index, &ch) in chars.iter().enumerate().take(end).skip(start) {
if !crate::renderer::composer::is_lang_neutral(ch) {
language = crate::renderer::style_resolver::detect_lang_category(ch);
}
result.languages[index] = language;
result.advances[index] = advance(index, language);
}
}
result
}
pub(super) fn width(&self, start: usize, end: usize) -> f64 {
self.advances[start..end].iter().sum()
}
pub(super) fn at(&self, index: usize) -> (usize, f64) {
(self.languages[index], self.advances[index])
}
}
pub(crate) struct InlineTableParagraphGeometry {
pub(crate) flow_bottom: f64,
pub(crate) content_bottom: f64,
pub(crate) line_box_bottom: f64,
}
impl InlineTableParagraphGeometry {
pub(crate) fn at_flow_origin(mut self, paint_origin: f64, flow_origin: f64) -> Self {
self.flow_bottom = flow_origin + (self.flow_bottom - paint_origin).max(0.0);
self.line_box_bottom += flow_origin - paint_origin;
self
}
}