use std::ops::Range;
use crate::paragraph::ShapedWord;
use crate::types::ShapedLine;
mod nav;
mod visual_lines;
mod wrap;
pub use wrap::{shape_document, wrap_document};
#[derive(Clone, Debug)]
pub struct ShapedParagraph {
pub words: Vec<ShapedWord>,
pub byte_range: Range<usize>,
}
#[derive(Clone, Debug)]
pub struct ShapedDocument {
pub paragraphs: Vec<ShapedParagraph>,
pub space_width: f32,
pub ascent_lpx: f32,
pub descent_lpx: f32,
pub line_height_lpx: f32,
}
#[derive(Clone, Debug)]
pub struct VisualLine {
pub line: ShapedLine,
pub byte_start: usize,
pub byte_end: usize,
}
#[derive(Clone, Debug)]
pub struct MultilineLayout {
pub lines: Vec<VisualLine>,
pub total_height_lpx: f32,
pub line_height_lpx: f32,
}
#[cfg(test)]
pub(crate) mod test_helpers {
use super::*;
use crate::types::{FontId, ShapedGlyph};
pub 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 fn vline(
glyphs: Vec<ShapedGlyph>,
byte_start: usize,
byte_end: usize,
y: f32,
) -> VisualLine {
let width: f32 = glyphs.iter().map(|g| g.x_advance_lpx).sum();
VisualLine {
line: ShapedLine {
glyphs,
width_lpx: width,
ascent_lpx: 10.0,
descent_lpx: -2.0,
y_offset_lpx: y,
base_direction: crate::types::Direction::Ltr,
runs: Vec::new(),
},
byte_start,
byte_end,
}
}
pub fn two_line_layout() -> MultilineLayout {
MultilineLayout {
lines: vec![
vline(vec![glyph(0, 5.0), glyph(1, 6.0)], 0, 3, 0.0),
vline(vec![glyph(3, 7.0), glyph(4, 8.0)], 3, 5, 12.0),
],
total_height_lpx: 24.0,
line_height_lpx: 12.0,
}
}
}