1use azul_core::geom::LogicalSize;
10
11#[cfg(all(feature = "text_layout", feature = "font_loading"))]
12pub use crate::text3::script::Language;
13#[cfg(all(feature = "text_layout", feature = "font_loading"))]
14pub use crate::text3::{
15 cache::{
16 AvailableSpace, BidiDirection, ContentIndex, FontHash, FontManager, FontSelector,
17 FontStyle, Glyph, ImageSource, InlineContent, InlineImage, InlineShape, TextShapingCache,
18 LayoutError, LayoutFontMetrics, LayoutFragment, ObjectFit, SegmentAlignment, ShapeBoundary,
19 ShapeDefinition, ShapedItem, Size, StyleProperties, StyledRun, UnifiedConstraints,
20 UnifiedLayout, VerticalMetrics,
21 },
22 script::Script,
23};
24
25#[cfg(all(feature = "text_layout", feature = "font_loading"))]
31pub use crate::text3::cache::TextShapingCache as LayoutCache;
32
33#[cfg(all(feature = "text_layout", feature = "font_loading"))]
34pub type TextLayoutCache = TextShapingCache;
35
36#[cfg(not(all(feature = "text_layout", feature = "font_loading")))]
37pub use stub::TextLayoutCache;
38
39pub trait ShallowClone {
41 fn shallow_clone(&self) -> Self;
43}
44
45pub trait ParsedFontTrait: Send + Clone + ShallowClone {
50 fn shape_text(
52 &self,
53 text: &str,
54 script: Script,
55 language: Language,
56 direction: BidiDirection,
57 style: &StyleProperties,
58 ) -> Result<Vec<Glyph>, LayoutError>;
59
60 fn get_hash(&self) -> u64;
62
63 fn get_glyph_size(&self, glyph_id: u16, font_size: f32) -> Option<LogicalSize>;
65
66 fn get_hyphen_glyph_and_advance(&self, font_size: f32) -> Option<(u16, f32)>;
68
69 fn get_kashida_glyph_and_advance(&self, font_size: f32) -> Option<(u16, f32)>;
71
72 fn has_glyph(&self, codepoint: u32) -> bool;
74
75 fn get_vertical_metrics(&self, glyph_id: u16) -> Option<VerticalMetrics>;
77
78 fn get_font_metrics(&self) -> LayoutFontMetrics;
80
81 fn num_glyphs(&self) -> u16;
83
84 fn get_space_width(&self) -> Option<usize>;
87}
88
89pub trait FontLoaderTrait<T>: Send + core::fmt::Debug {
94 fn load_font(&self, font_bytes: &[u8], font_index: usize) -> Result<T, LayoutError>;
95}
96
97#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
99pub struct FontId(pub u64);
100
101pub trait FontSystemTrait: Send + Sync {
106 type FallbackChain: FontFallbackChainTrait;
108
109 fn resolve_char(&self, chain: &Self::FallbackChain, c: char) -> Option<FontId>;
111
112 fn get_font_data(&self, font_id: FontId) -> Option<alloc::vec::Vec<u8>>;
114
115 fn get_font_index(&self, font_id: FontId) -> usize;
117}
118
119pub trait FontFallbackChainTrait: Clone + Send + Sync {
121 fn is_empty(&self) -> bool;
123
124 fn primary_font_id(&self) -> Option<FontId>;
126}
127
128#[cfg(not(all(feature = "text_layout", feature = "font_loading")))]
130pub use stub::*;
131
132#[cfg(not(all(feature = "text_layout", feature = "font_loading")))]
133mod stub {
134 use super::*;
135
136 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
137 pub struct Script;
138
139 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
140 pub struct Language;
141
142 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
143 pub enum FontStyle {
144 Normal,
145 Italic,
146 Oblique,
147 }
148
149 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
151 pub enum BidiDirection {
152 Ltr,
153 Rtl,
154 }
155
156 #[derive(Debug, Clone)]
157 pub struct StyleProperties;
158
159 #[derive(Debug, Clone)]
160 pub struct Glyph;
161
162 #[derive(Debug, Clone, Copy)]
163 pub struct VerticalMetrics {
164 pub ascent: f32,
165 pub descent: f32,
166 pub line_gap: f32,
167 }
168
169 #[derive(Debug, Clone, Copy)]
170 pub struct LayoutFontMetrics {
171 pub ascent: f32,
172 pub descent: f32,
173 pub line_gap: f32,
174 pub units_per_em: u16,
175 pub x_height: Option<f32>,
176 pub cap_height: Option<f32>,
177 }
178
179 #[derive(Debug, Clone)]
180 pub struct LayoutError;
181
182 #[derive(Debug, Clone)]
183 pub struct FontSelector;
184
185 #[derive(Debug)]
186 pub struct FontManager;
187
188 #[derive(Debug)]
189 pub struct LayoutCache;
190
191 pub type ContentIndex = usize;
193 pub type FontHash = u64;
194
195 #[derive(Debug, Clone)]
196 pub struct InlineContent;
197
198 #[derive(Debug, Clone)]
199 pub struct StyledRun;
200
201 #[derive(Debug, Clone)]
202 pub struct LayoutFragment;
203
204 #[derive(Debug, Clone)]
205 pub struct UnifiedConstraints;
206
207 #[derive(Debug, Clone)]
208 pub struct InlineImage;
209
210 #[derive(Debug, Clone)]
211 pub struct InlineShape;
212
213 #[derive(Debug, Clone)]
214 pub struct ShapeDefinition;
215
216 #[derive(Debug, Clone)]
217 pub struct ShapeBoundary;
218
219 #[derive(Debug, Clone)]
220 pub struct ShapedItem;
221
222 #[derive(Debug, Clone)]
223 pub enum ImageSource {
224 Ref(azul_core::resources::ImageRef),
225 Url(String),
226 Data(std::sync::Arc<[u8]>),
227 Svg(std::sync::Arc<str>),
228 Placeholder(Size),
229 }
230
231 #[derive(Debug, Clone, Copy)]
232 pub enum ObjectFit {
233 Contain,
234 Cover,
235 Fill,
236 None,
237 ScaleDown,
238 }
239
240 #[derive(Debug, Clone, Copy)]
241 pub enum SegmentAlignment {
242 Start,
243 Center,
244 End,
245 }
246
247 #[derive(Debug, Clone)]
248 pub struct UnifiedLayout;
249
250 pub type TextLayoutCache = LayoutCache;
251
252 pub type Size = azul_core::geom::LogicalSize;
253}