use super::*;
#[derive(Clone, Data, Debug)]
pub struct GlyphAtlas {
#[get(pub(crate))]
#[get_mut(pub(crate))]
#[set(pub(crate))]
pub(crate) canvas: HtmlCanvasElement,
#[get(pub(crate))]
#[get_mut(pub(crate))]
#[set(pub(crate))]
pub(crate) context: CanvasRenderingContext2d,
#[get(pub(crate))]
#[get_mut(pub(crate))]
#[set(pub(crate))]
pub(crate) entries: HashMap<GlyphKey, GlyphEntry>,
#[get(pub(crate), type(copy))]
#[get_mut(pub(crate))]
#[set(pub(crate))]
pub(crate) cursor_x: f32,
#[get(pub(crate), type(copy))]
#[get_mut(pub(crate))]
#[set(pub(crate))]
pub(crate) cursor_y: f32,
#[get(pub(crate), type(copy))]
#[get_mut(pub(crate))]
#[set(pub(crate))]
pub(crate) shelf_height: f32,
#[get(pub(crate), type(copy))]
#[get_mut(pub(crate))]
#[set(pub(crate))]
pub(crate) width: u32,
#[get(pub(crate), type(copy))]
#[get_mut(pub(crate))]
#[set(pub(crate))]
pub(crate) height: u32,
#[get(pub(crate), type(copy))]
#[get_mut(pub(crate))]
#[set(pub(crate))]
pub(crate) dirty: bool,
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct GlyphQuad {
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub u: f32,
pub v: f32,
pub u_size: f32,
pub v_size: f32,
pub color: u32,
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct TextLine {
pub text: String,
pub left: f64,
pub baseline: f64,
pub width: f64,
}
#[derive(Clone, Debug, Default, PartialEq)]
pub struct TextRun {
pub quads: Vec<GlyphQuad>,
pub lines: Vec<TextLine>,
pub width: f64,
pub height: f64,
pub ascent: f64,
pub descent: f64,
pub line_height: f64,
pub line_count: usize,
}
#[derive(Clone, Data, Debug)]
pub struct TextShaper {
pub measurer: TextMeasurer,
pub atlas: GlyphAtlas,
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct TextMetrics {
pub width: f64,
pub height: f64,
pub ascent: f64,
pub descent: f64,
pub line_height: f64,
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct GlyphEntry {
pub u: f32,
pub v: f32,
pub width: f32,
pub height: f32,
pub bearing_x: f32,
pub bearing_y: f32,
pub advance: f32,
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct GlyphKey {
pub character: char,
pub font: String,
}
#[derive(Clone, Data)]
pub struct TextMeasurer {
#[get(pub(crate))]
#[get_mut(pub(crate))]
#[set(pub(crate))]
pub(crate) context: Option<CanvasRenderingContext2d>,
#[get(pub(crate))]
#[get_mut(pub(crate))]
#[set(pub(crate))]
pub(crate) cache: Rc<RefCell<HashMap<(String, String), TextMetrics>>>,
}