use zenith_core::{FontProvider, FontStyle};
use crate::error::LayoutError;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TextDirection {
#[default]
Ltr,
Rtl,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShapeRequest<'a> {
pub text: &'a str,
pub families: &'a [String],
pub weight: u16,
pub style: FontStyle,
pub font_size: f32,
pub direction: TextDirection,
}
#[derive(Debug, Clone, PartialEq)]
pub struct PositionedGlyph {
pub glyph_id: u16,
pub x: f32,
pub y: f32,
pub text: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ZenithGlyphRun {
pub font_id: String,
pub font_size: f32,
pub ascent: f32,
pub descent: f32,
pub line_height: f32,
pub advance_width: f32,
pub glyphs: Vec<PositionedGlyph>,
}
pub struct FallbackResult {
pub runs: Vec<ZenithGlyphRun>,
pub missing_chars: Vec<char>,
}
pub trait TextLayoutEngine {
fn shape(
&self,
req: &ShapeRequest<'_>,
provider: &dyn FontProvider,
) -> Result<ZenithGlyphRun, LayoutError>;
fn shape_with_fallback(
&self,
req: &ShapeRequest<'_>,
provider: &dyn FontProvider,
) -> Result<FallbackResult, LayoutError>;
}