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