1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//! Astrelis Text - Text rendering with cosmic-text
//!
//! This crate provides modular text rendering capabilities:
//! - Font management with system fonts and custom fonts
//! - Text builder with styling (size, color, alignment, etc.)
//! - GPU-accelerated text rendering with zero-cost backend selection
//! - Signed Distance Field (SDF) rendering for scalable text and effects
//!
//! ## Zero-Cost Renderer Selection
//!
//! Choose the renderer that fits your memory budget:
//!
//! | Renderer | Memory | Use Case |
//! |----------|--------|----------|
//! | [`BitmapTextRenderer`] | ~8 MB | Small text, UI labels, no effects needed |
//! | [`SdfTextRenderer`] | ~8 MB | Large text, titles, needs shadows/outlines/glows |
//! | [`FontRenderer`] | ~16 MB | Mixed usage, backwards compatibility (default) |
//!
//! Memory can be further reduced with [`TextRendererConfig`]:
//! - `small()`: 512x512 atlas (~1 MB per renderer)
//! - `medium()`: 1024x1024 atlas (~4 MB per renderer)
//! - `large()`: 2048x2048 atlas (~8 MB per renderer, default)
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use astrelis_text::{FontSystem, FontRenderer, Text, Color};
//! use astrelis_render::GraphicsContext;
//! use astrelis_core::math::Vec2;
//!
//! let context = GraphicsContext::new_owned_sync().expect("Failed to create graphics context");
//! let font_system = FontSystem::with_system_fonts();
//! let mut renderer = FontRenderer::new(context, font_system);
//!
//! // Create styled text with builder pattern
//! let text = Text::new("Hello, World!")
//! .size(24.0)
//! .color(Color::WHITE)
//! .bold();
//!
//! // Prepare and draw
//! let mut buffer = renderer.prepare(&text);
//! renderer.draw_text(&mut buffer, Vec2::new(100.0, 100.0));
//!
//! // Render to a render pass
//! // renderer.render(render_pass, viewport_size);
//! ```
//!
//! ## Features
//!
//! - **System Fonts**: Automatically loads all system fonts
//! - **Custom Fonts**: Load .ttf and .otf files from disk or memory
//! - **Rich Styling**: Font size, weight, style, color, alignment, wrapping
//! - **Builder Pattern**: Fluent API for text configuration
//! - **GPU Accelerated**: WGPU-based rendering with texture atlas
//! - **Text Layout**: Multi-line text with automatic wrapping
//! - **Asset Integration**: Load fonts through the asset system (with `asset` feature)
//! - **SDF Rendering**: Resolution-independent text scaling and effects
//! - **Text Effects**: Shadows, outlines, glows, and more
//!
//! ## SDF (Signed Distance Field) Rendering
//!
//! SDF rendering enables sharp text at any scale and high-quality effects. The renderer uses
//! a hybrid approach for optimal quality:
//!
//! - **Bitmap atlas** for small text (< 24px) without effects - sharper at small sizes
//! - **SDF atlas** for large text (>= 24px) or text with effects - scalable and smooth
//!
//! ### When to Use SDF
//!
//! SDF rendering is automatically enabled for:
//! - Large text (24px and above)
//! - Text with effects (shadows, outlines, glows)
//! - Text that needs to scale dynamically
//!
//! ### Basic SDF Usage
//!
//! ```rust,no_run
//! use astrelis_text::{Text, TextEffect, Color};
//! use astrelis_core::math::Vec2;
//!
//! // Text with a drop shadow
//! let text = Text::new("Hello")
//! .size(32.0)
//! .with_shadow(Vec2::new(2.0, 2.0), Color::rgba(0.0, 0.0, 0.0, 0.5));
//!
//! // Text with an outline
//! let text = Text::new("Bold")
//! .size(48.0)
//! .with_outline(2.0, Color::BLACK);
//!
//! // Combine multiple effects
//! let text = Text::new("Glowing")
//! .size(36.0)
//! .with_shadow(Vec2::new(1.0, 1.0), Color::BLACK)
//! .with_outline(1.5, Color::WHITE)
//! .with_glow(4.0, Color::BLUE, 0.8);
//! ```
//!
//! ### Force SDF Mode
//!
//! You can force SDF rendering for better scalability:
//!
//! ```rust,no_run
//! use astrelis_text::Text;
//!
//! let text = Text::new("Scalable")
//! .size(16.0)
//! .sdf(); // Force SDF even for small text
//! ```
//!
//! ## Examples
//!
//! Run the examples to see text rendering in action:
//!
//! ```bash
//! cargo run --package astrelis-text --example text_demo
//! cargo run --package astrelis-text --example text_effects
//! cargo run --package astrelis-text --example rich_text_demo
//! ```
// Re-export main types
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
// Re-export asset types when feature is enabled
pub use ;
// Re-export cosmic-text types needed for retained rendering
pub use CacheKey;
// Re-export Color from astrelis-render
pub use Color;
// Re-export math types from astrelis-core
pub use Vec2;