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 #[must_use]
43 fn shallow_clone(&self) -> Self;
44}
45
46pub trait ParsedFontTrait: Send + Clone + ShallowClone {
51 fn shape_text(
56 &self,
57 text: &str,
58 script: Script,
59 language: Language,
60 direction: BidiDirection,
61 style: &StyleProperties,
62 ) -> Result<Vec<Glyph>, LayoutError>;
63
64 fn get_hash(&self) -> u64;
66
67 fn get_glyph_size(&self, glyph_id: u16, font_size: f32) -> Option<LogicalSize>;
69
70 fn get_hyphen_glyph_and_advance(&self, font_size: f32) -> Option<(u16, f32)>;
72
73 fn get_kashida_glyph_and_advance(&self, font_size: f32) -> Option<(u16, f32)>;
75
76 fn has_glyph(&self, codepoint: u32) -> bool;
78
79 fn get_vertical_metrics(&self, glyph_id: u16) -> Option<VerticalMetrics>;
81
82 fn get_font_metrics(&self) -> LayoutFontMetrics;
84
85 fn num_glyphs(&self) -> u16;
87
88 fn get_space_width(&self) -> Option<usize>;
91}
92
93pub trait FontLoaderTrait<T>: Send + core::fmt::Debug {
98 fn load_font(&self, font_bytes: &[u8], font_index: usize) -> Result<T, LayoutError>;
102}
103
104#[cfg(not(all(feature = "text_layout", feature = "font_loading")))]
106pub use stub::*;
107
108#[cfg(not(all(feature = "text_layout", feature = "font_loading")))]
109mod stub {
110 use super::*;
111
112 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
113 pub struct Script;
114
115 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
116 pub struct Language;
117
118 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
119 pub enum FontStyle {
120 Normal,
121 Italic,
122 Oblique,
123 }
124
125 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
127 pub enum BidiDirection {
128 Ltr,
129 Rtl,
130 }
131
132 #[derive(Debug, Clone)]
133 pub struct StyleProperties;
134
135 #[derive(Debug, Clone)]
136 pub struct Glyph;
137
138 #[derive(Debug, Clone, Copy)]
139 pub struct VerticalMetrics {
140 pub ascent: f32,
141 pub descent: f32,
142 pub line_gap: f32,
143 }
144
145 #[derive(Debug, Clone, Copy)]
146 pub struct LayoutFontMetrics {
147 pub ascent: f32,
148 pub descent: f32,
149 pub line_gap: f32,
150 pub units_per_em: u16,
151 pub x_height: Option<f32>,
152 pub cap_height: Option<f32>,
153 }
154
155 #[derive(Debug, Clone)]
156 pub struct LayoutError;
157
158 #[derive(Debug, Clone)]
159 pub struct FontSelector;
160
161 #[derive(Debug)]
162 pub struct FontManager;
163
164 #[derive(Debug)]
165 pub struct LayoutCache;
166
167 pub type ContentIndex = usize;
169 pub type FontHash = u64;
170
171 #[derive(Debug, Clone)]
172 pub struct InlineContent;
173
174 #[derive(Debug, Clone)]
175 pub struct StyledRun;
176
177 #[derive(Debug, Clone)]
178 pub struct LayoutFragment;
179
180 #[derive(Debug, Clone)]
181 pub struct UnifiedConstraints;
182
183 #[derive(Debug, Clone)]
184 pub struct InlineImage;
185
186 #[derive(Debug, Clone)]
187 pub struct InlineShape;
188
189 #[derive(Debug, Clone)]
190 pub struct ShapeDefinition;
191
192 #[derive(Debug, Clone)]
193 pub struct ShapeBoundary;
194
195 #[derive(Debug, Clone)]
196 pub struct ShapedItem;
197
198 #[derive(Debug, Clone)]
199 pub enum ImageSource {
200 Ref(azul_core::resources::ImageRef),
201 Url(String),
202 Data(std::sync::Arc<[u8]>),
203 Svg(std::sync::Arc<str>),
204 Placeholder(Size),
205 }
206
207 #[derive(Debug, Clone, Copy)]
208 pub enum ObjectFit {
209 Contain,
210 Cover,
211 Fill,
212 None,
213 ScaleDown,
214 }
215
216 #[derive(Debug, Clone, Copy)]
217 pub enum SegmentAlignment {
218 Start,
219 Center,
220 End,
221 }
222
223 #[derive(Debug, Clone)]
224 pub struct UnifiedLayout;
225
226 pub type TextLayoutCache = LayoutCache;
227
228 pub type Size = azul_core::geom::LogicalSize;
229}