55
66use azul_core:: geom:: LogicalSize ;
77
8- #[ cfg( feature = "text_layout" ) ]
8+ #[ cfg( all ( feature = "text_layout" , feature = "font_loading" ) ) ]
99pub use crate :: text3:: script:: Language ;
10- #[ cfg( feature = "text_layout" ) ]
10+ #[ cfg( all ( feature = "text_layout" , feature = "font_loading" ) ) ]
1111pub use crate :: text3:: {
1212 cache:: {
1313 AvailableSpace , BidiDirection , ContentIndex , FontHash , FontManager , FontSelector ,
@@ -19,8 +19,12 @@ pub use crate::text3::{
1919 script:: Script ,
2020} ;
2121
22+ #[ cfg( all( feature = "text_layout" , feature = "font_loading" ) ) ]
2223pub type TextLayoutCache = LayoutCache ;
2324
25+ #[ cfg( not( all( feature = "text_layout" , feature = "font_loading" ) ) ) ]
26+ pub use stub:: TextLayoutCache ;
27+
2428/// Trait for types that support cheap, shallow cloning (e.g., reference-counted types).
2529pub trait ShallowClone {
2630 /// Create a shallow clone (increment reference count, don't copy data)
@@ -67,11 +71,42 @@ pub trait FontLoaderTrait<T>: Send + core::fmt::Debug {
6771 fn load_font ( & self , font_bytes : & [ u8 ] , font_index : usize ) -> Result < T , LayoutError > ;
6872}
6973
70- // When text_layout is disabled, provide minimal stub types
71- #[ cfg( not( feature = "text_layout" ) ) ]
74+ /// Opaque font identifier - wraps the underlying font system's ID type
75+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
76+ pub struct FontId ( pub u64 ) ;
77+
78+ /// Trait for font system abstraction (font discovery, fallback chains).
79+ ///
80+ /// This abstracts over the underlying font system (e.g., rust_fontconfig, fontdb)
81+ /// allowing text3 to work with or without system font discovery.
82+ pub trait FontSystemTrait : Send + Sync {
83+ /// The type of font fallback chain this system uses
84+ type FallbackChain : FontFallbackChainTrait ;
85+
86+ /// Resolve a character to a font ID using the fallback chain
87+ fn resolve_char ( & self , chain : & Self :: FallbackChain , c : char ) -> Option < FontId > ;
88+
89+ /// Get the font data (bytes) for a font ID
90+ fn get_font_data ( & self , font_id : FontId ) -> Option < alloc:: vec:: Vec < u8 > > ;
91+
92+ /// Get the font index within the font file
93+ fn get_font_index ( & self , font_id : FontId ) -> usize ;
94+ }
95+
96+ /// Trait for font fallback chains
97+ pub trait FontFallbackChainTrait : Clone + Send + Sync {
98+ /// Check if the chain is empty
99+ fn is_empty ( & self ) -> bool ;
100+
101+ /// Get the primary font ID (if any)
102+ fn primary_font_id ( & self ) -> Option < FontId > ;
103+ }
104+
105+ // When text_layout or font_loading is disabled, provide minimal stub types
106+ #[ cfg( not( all( feature = "text_layout" , feature = "font_loading" ) ) ) ]
72107pub use stub:: * ;
73108
74- #[ cfg( not( feature = "text_layout" ) ) ]
109+ #[ cfg( not( all ( feature = "text_layout" , feature = "font_loading" ) ) ) ]
75110mod stub {
76111 use super :: * ;
77112
@@ -94,13 +129,18 @@ mod stub {
94129 RightToLeft ,
95130 }
96131
132+ /// Stub for BidiDirection when text_layout is disabled
133+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
134+ pub enum BidiDirection {
135+ Ltr ,
136+ Rtl ,
137+ }
138+
97139 #[ derive( Debug , Clone ) ]
98140 pub struct StyleProperties ;
99141
100142 #[ derive( Debug , Clone ) ]
101- pub struct Glyph < T > {
102- _phantom : core:: marker:: PhantomData < T > ,
103- }
143+ pub struct Glyph ;
104144
105145 #[ derive( Debug , Clone , Copy ) ]
106146 pub struct VerticalMetrics {
@@ -124,14 +164,10 @@ mod stub {
124164 pub struct FontSelector ;
125165
126166 #[ derive( Debug ) ]
127- pub struct FontManager < T , Q > {
128- _phantom : core:: marker:: PhantomData < ( T , Q ) > ,
129- }
167+ pub struct FontManager ;
130168
131169 #[ derive( Debug ) ]
132- pub struct LayoutCache < T > {
133- _phantom : core:: marker:: PhantomData < T > ,
134- }
170+ pub struct LayoutCache ;
135171
136172 // Additional stub types needed by solver3
137173 pub type ContentIndex = usize ;
@@ -186,7 +222,7 @@ mod stub {
186222 #[ derive( Debug , Clone ) ]
187223 pub struct UnifiedLayout ;
188224
189- pub type TextLayoutCache = LayoutCache < ( ) > ;
225+ pub type TextLayoutCache = LayoutCache ;
190226
191227 pub type Size = azul_core:: geom:: LogicalSize ;
192228}
0 commit comments