50 lines
2.1 KiB
Markdown
50 lines
2.1 KiB
Markdown
|
|
# hcie-text
|
||
|
|
|
||
|
|
A specialized Rust library for high-quality text rendering and layer generation, designed for integration into image editing software.
|
||
|
|
|
||
|
|
## Project Summary
|
||
|
|
`hcie-text` provides the core logic for converting text strings into rasterized pixel data and `Layer` objects. It leverages the `fontdue` crate for efficient and accurate glyph rendering, allowing users to load custom fonts, specify text styles, and output RGBA buffers ready for canvas composition.
|
||
|
|
|
||
|
|
## Usage Guide
|
||
|
|
|
||
|
|
### Basic Workflow
|
||
|
|
1. **Initialize**: Create a `TextRenderer` instance.
|
||
|
|
2. **Load Fonts**: Load one or more `.ttf` or `.otf` fonts using `load_font(name, data)`.
|
||
|
|
3. **Render**: Use `rasterize_text` to get a raw RGBA pixel buffer and the dimensions of the rendered text.
|
||
|
|
4. **Layer Creation**: Use `create_text_layer` to generate a `Layer` object compatible with the `hcie-protocol`.
|
||
|
|
|
||
|
|
### Key API
|
||
|
|
- `TextRenderer::new()`: Initializes the renderer.
|
||
|
|
- `load_font(&mut self, name: &str, data: &[u8])`: Registers a font by name.
|
||
|
|
- `rasterize_text(&mut self, text: &str, font_name: &str, size: f32, color: [u8; 4])`: Returns `(Vec<u8>, width, height)`.
|
||
|
|
- `create_text_layer(&mut self, text: &str, font: &str, size: f32, color: [u8; 4])`: Creates a `Layer` with `LayerType::Text`.
|
||
|
|
|
||
|
|
## AI Agent Instructions
|
||
|
|
When working on this library or integrating it:
|
||
|
|
- **Font Management**: Always verify that a font is loaded via `has_font()` or ensure `load_font()` was called before attempting to rasterize.
|
||
|
|
- **Coordinates**: The library uses a `PositiveYDown` coordinate system, consistent with standard image buffers.
|
||
|
|
- **Layering**: When creating layers, ensure the dimensions match the intended canvas or are handled by the compositor.
|
||
|
|
- **Protocol Alignment**: Ensure all `Layer` outputs strictly follow the `hcie-protocol` definitions.
|
||
|
|
|
||
|
|
## Development and Testing
|
||
|
|
|
||
|
|
### Prerequisites
|
||
|
|
- Rust toolchain (latest stable)
|
||
|
|
|
||
|
|
### Commands
|
||
|
|
**Build the library:**
|
||
|
|
```bash
|
||
|
|
cargo build
|
||
|
|
```
|
||
|
|
|
||
|
|
**Run tests:**
|
||
|
|
```bash
|
||
|
|
cargo test
|
||
|
|
```
|
||
|
|
|
||
|
|
**Run the test GUI example:**
|
||
|
|
```bash
|
||
|
|
cargo run --example text_test
|
||
|
|
```
|
||
|
|
*(Note: The example requires system fonts to be available at standard Linux paths like `/usr/share/fonts`)*
|