mod bidi_runs;
mod caret;
mod hit_test;
mod shape_utils;
pub use caret::{
pixel_x_at_byte, run_caret_x, run_caret_x_at, run_caret_x_at_affinity, run_selection_rects,
visual_caret_step, visual_line_edge,
};
pub use hit_test::{byte_at_pixel_x, run_byte_at_x};
#[cfg(test)]
pub(super) mod test_support {
use crate::ShapedLine;
use crate::types::{Direction, FontId, RunSpan, ShapedGlyph};
pub(crate) fn glyph(cluster: u32, adv: f32) -> ShapedGlyph {
ShapedGlyph {
glyph_id: 1,
font_id: FontId::PRIMARY,
font_handle: crate::FontHandle::default(),
x_advance_lpx: adv,
position_lpx: [0.0, 0.0],
cluster,
direction: crate::types::Direction::Ltr,
}
}
pub(crate) fn line(glyphs: Vec<ShapedGlyph>) -> ShapedLine {
let width: f32 = glyphs.iter().map(|g| g.x_advance_lpx).sum();
ShapedLine {
glyphs,
width_lpx: width,
ascent_lpx: 10.0,
descent_lpx: -2.0,
y_offset_lpx: 0.0,
base_direction: crate::types::Direction::Ltr,
runs: Vec::new(),
}
}
pub(crate) fn dglyph(cluster: u32, adv: f32, dir: Direction) -> ShapedGlyph {
ShapedGlyph {
direction: dir,
..glyph(cluster, adv)
}
}
pub(crate) fn run_line(glyphs: Vec<ShapedGlyph>, runs: Vec<RunSpan>) -> ShapedLine {
let width: f32 = glyphs.iter().map(|g| g.x_advance_lpx).sum();
ShapedLine {
glyphs,
width_lpx: width,
ascent_lpx: 10.0,
descent_lpx: -2.0,
y_offset_lpx: 0.0,
base_direction: Direction::Rtl,
runs,
}
}
pub(crate) fn run(range: std::ops::Range<usize>, dir: Direction) -> RunSpan {
RunSpan {
level: if dir == Direction::Rtl { 1 } else { 0 },
byte_range: range,
direction: dir,
}
}
}