use azul_core::geom::LogicalSize;
#[cfg(all(feature = "text_layout", feature = "font_loading"))]
pub use crate::text3::script::Language;
#[cfg(all(feature = "text_layout", feature = "font_loading"))]
pub use crate::text3::{
cache::{
AvailableSpace, BidiDirection, ContentIndex, FontHash, FontManager, FontSelector,
FontStyle, Glyph, ImageSource, InlineContent, InlineImage, InlineShape, LayoutCache,
LayoutError, LayoutFontMetrics, LayoutFragment, ObjectFit, SegmentAlignment, ShapeBoundary,
ShapeDefinition, ShapedItem, Size, StyleProperties, StyledRun, UnifiedConstraints,
UnifiedLayout, VerticalMetrics,
},
script::Script,
};
#[cfg(all(feature = "text_layout", feature = "font_loading"))]
pub type TextLayoutCache = LayoutCache;
#[cfg(not(all(feature = "text_layout", feature = "font_loading")))]
pub use stub::TextLayoutCache;
pub trait ShallowClone {
fn shallow_clone(&self) -> Self;
}
pub trait ParsedFontTrait: Send + Clone + ShallowClone {
fn shape_text(
&self,
text: &str,
script: Script,
language: Language,
direction: BidiDirection,
style: &StyleProperties,
) -> Result<Vec<Glyph>, LayoutError>;
fn get_hash(&self) -> u64;
fn get_glyph_size(&self, glyph_id: u16, font_size: f32) -> Option<LogicalSize>;
fn get_hyphen_glyph_and_advance(&self, font_size: f32) -> Option<(u16, f32)>;
fn get_kashida_glyph_and_advance(&self, font_size: f32) -> Option<(u16, f32)>;
fn has_glyph(&self, codepoint: u32) -> bool;
fn get_vertical_metrics(&self, glyph_id: u16) -> Option<VerticalMetrics>;
fn get_font_metrics(&self) -> LayoutFontMetrics;
fn num_glyphs(&self) -> u16;
}
pub trait FontLoaderTrait<T>: Send + core::fmt::Debug {
fn load_font(&self, font_bytes: &[u8], font_index: usize) -> Result<T, LayoutError>;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FontId(pub u64);
pub trait FontSystemTrait: Send + Sync {
type FallbackChain: FontFallbackChainTrait;
fn resolve_char(&self, chain: &Self::FallbackChain, c: char) -> Option<FontId>;
fn get_font_data(&self, font_id: FontId) -> Option<alloc::vec::Vec<u8>>;
fn get_font_index(&self, font_id: FontId) -> usize;
}
pub trait FontFallbackChainTrait: Clone + Send + Sync {
fn is_empty(&self) -> bool;
fn primary_font_id(&self) -> Option<FontId>;
}
#[cfg(not(all(feature = "text_layout", feature = "font_loading")))]
pub use stub::*;
#[cfg(not(all(feature = "text_layout", feature = "font_loading")))]
mod stub {
use super::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Script;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Language;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FontStyle {
Normal,
Italic,
Oblique,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TextDirection {
LeftToRight,
RightToLeft,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BidiDirection {
Ltr,
Rtl,
}
#[derive(Debug, Clone)]
pub struct StyleProperties;
#[derive(Debug, Clone)]
pub struct Glyph;
#[derive(Debug, Clone, Copy)]
pub struct VerticalMetrics {
pub ascent: f32,
pub descent: f32,
pub line_gap: f32,
}
#[derive(Debug, Clone, Copy)]
pub struct LayoutFontMetrics {
pub ascent: f32,
pub descent: f32,
pub line_gap: f32,
pub units_per_em: u16,
}
#[derive(Debug, Clone)]
pub struct LayoutError;
#[derive(Debug, Clone)]
pub struct FontSelector;
#[derive(Debug)]
pub struct FontManager;
#[derive(Debug)]
pub struct LayoutCache;
pub type ContentIndex = usize;
pub type FontHash = u64;
#[derive(Debug, Clone)]
pub struct InlineContent;
#[derive(Debug, Clone)]
pub struct StyledRun;
#[derive(Debug, Clone)]
pub struct LayoutFragment;
#[derive(Debug, Clone)]
pub struct UnifiedConstraints;
#[derive(Debug, Clone)]
pub struct InlineImage;
#[derive(Debug, Clone)]
pub struct InlineShape;
#[derive(Debug, Clone)]
pub struct ShapeDefinition;
#[derive(Debug, Clone)]
pub struct ShapeBoundary;
#[derive(Debug, Clone)]
pub struct ShapedItem;
#[derive(Debug, Clone)]
pub enum ImageSource {
Ref(azul_core::resources::ImageRef),
Url(String),
Data(std::sync::Arc<[u8]>),
Svg(std::sync::Arc<str>),
Placeholder(Size),
}
#[derive(Debug, Clone, Copy)]
pub enum ObjectFit {
Contain,
Cover,
Fill,
None,
ScaleDown,
}
#[derive(Debug, Clone, Copy)]
pub enum SegmentAlignment {
Start,
Center,
End,
}
#[derive(Debug, Clone)]
pub struct UnifiedLayout;
pub type TextLayoutCache = LayoutCache;
pub type Size = azul_core::geom::LogicalSize;
}