Commit f626613
committed
Merge torrust#833: refactor: replace text-to-png with internal render-text-as-image and modernize codebase
f326874 test: add comprehensive test coverage for render-text-as-image and related components (Cameron Garnham)
67e411f refactor: replace text-to-png with internal render-text-as-image and modernize codebase (Cameron Garnham)
Pull request description:
Replace the external `text-to-png` dependency with a new internal `render-text-as-image` package, modernizes the codebase by migrating from `lazy_static` to `std::sync::LazyLock`, relocates unit tests to a centralized `src/tests/` directory, and bumps the minimum Rust version from 1.72 to 1.80.
## Key Changes
### Dependency Modernization
- **Replaced `text-to-png`** with new internal `render-text-as-image` package
- Pure-Rust text-to-PNG rendering using `ab_glyph` + `image` crates
- Embedded Roboto Mono font (no system dependencies)
- Eliminates heavy SVG rendering pipeline (resvg, usvg, fontdb, rustybuzz, etc.)
- Reduces transitive dependencies by ~30+ crates
- **Replaced `lazy_static`** with `std::sync::LazyLock` (stable since Rust 1.80)
- **Updated `io::Error::new(...)`** to `io::Error::other(...)` (stable since Rust 1.74)
- **Consolidated `bitflags`** from v1 + v2 to v2 only
- **Bumped minimum Rust version** from 1.72 to 1.80 (required for LazyLock)
### New Internal Package: `render-text-as-image`
- Self-contained text rendering library for containerized environments
- Modular architecture: blend, encode, font, layout, render, types modules
- Comprehensive documentation: specification (§SPEC R-1) and ADRs (001–003)
- Includes embedded Roboto Mono Regular font (125KB TTF)
- Designed for CAPTCHA, image generation, and similar use cases
### Test Architecture Reorganization
- **Moved inline `#[cfg(test)]` modules** to centralized `src/tests/` directory
- Follows project convention of separating crate-level tests from source
- Affected modules: config, cache, mailer, models, services, tracker, utils
- Updated `src/lib.rs` to include `mod tests;` for test discovery
- Some items widened to `pub(crate)` visibility to support test access
### Workspace Configuration
- Converted project to Cargo workspace with three members:
- Main `torrust-index` crate
- `located-error` package
- `render-text-as-image` package
- Updated `Cargo.toml` with workspace inheritance for metadata
### Code Quality Improvements
- **Fixed recurring typos**: "migth" → "might", "becuase" → "because", "successfull" → "successful", "Ununauthorized" → "Unauthorized"
- Updated `.gitignore` to exclude test report files
- Updated `cspell.json` and `project-words.txt` with new vocabulary
- Expanded `AGENTS.md` with detailed development guidelines
## Benefits
- **Reduced dependency tree**: ~30+ transitive crates removed
- **Modern Rust idioms**: Uses stable stdlib features (LazyLock, io::Error::other)
- **Better test organization**: Clear separation between source and test code
- **Self-contained text rendering**: No external system dependencies (FreeType, Fontconfig)
- **Improved compile times**: Smaller dependency graph and modular test structure
## Testing Performed
- All existing tests continue to pass after migration
- New `render-text-as-image` package includes comprehensive unit tests
- Crate test structure validated with `cargo test --workspace`
## Breaking Changes
- **Minimum Rust version increased from 1.72 to 1.80**
- Required for `std::sync::LazyLock` and `io::Error::other()`
- Rust 1.80 was released in July 2024 (~1.5 years ago)
- No API changes to public interfaces
## Migration Needed
- Developers must update to Rust 1.80+ to build the project
- New test contributions should follow the centralized `src/tests/` pattern
- Text rendering functionality now uses the internal `render-text-as-image` API
## References
- `std::sync::LazyLock` stabilization (Rust 1.80, July 2024)
- `io::Error::other()` stabilization (Rust 1.74, October 2023)
- Specification for render-text-as-image (§SPEC R-1)
- ADR 001–003 for dependency, font, and structure decisions
ACKs for top commit:
da2ce7:
ACK f326874
Tree-SHA512: 97db8fa981a5538807611c46b39f118d1aee617eda7ca324b713a3793b17294f0550f9ec8e06d0a6b06657012826d2c60c0eaca9501759918d9953d76d69681b74 files changed
Lines changed: 2187 additions & 1490 deletions
File tree
- .github/workflows
- docs/adrs
- packages
- located-error/src
- render-text-as-image
- adr
- assets
- docs
- examples
- src
- tests
- src
- bin
- bootstrap
- cache
- config
- v2
- models
- services
- tests
- bootstrap
- cache
- config
- v2
- models
- services
- tracker
- ui
- utils
- tracker
- ui
- utils
- web/api/server/v1/contexts/proxy
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 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 | + | |
0 commit comments