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
- Initialize: Create a
TextRendererinstance. - Load Fonts: Load one or more
.ttfor.otffonts usingload_font(name, data). - Render: Use
rasterize_textto get a raw RGBA pixel buffer and the dimensions of the rendered text. - Layer Creation: Use
create_text_layerto generate aLayerobject compatible with thehcie-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 aLayerwithLayerType::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 ensureload_font()was called before attempting to rasterize. - Coordinates: The library uses a
PositiveYDowncoordinate 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
Layeroutputs strictly follow thehcie-protocoldefinitions.
Development and Testing
Prerequisites
- Rust toolchain (latest stable)
Commands
Build the library:
cargo build
Run tests:
cargo test
Run the test GUI example:
cargo run --example text_test
(Note: The example requires system fonts to be available at standard Linux paths like /usr/share/fonts)