Expand description
A font-embedded text renderer for obscure characters, scripts, and emojis, built for maximum portability.
This crate enables rendering of virtually any Unicode character, including rare scripts and
emojis, without relying on system fonts or external resources.
It’s powered by cosmic-text for shaping and layout, with bundled Noto fonts
and emoji assets via twemoji-assets.
All assets are included in the binary, which increases its size (~35MB in release builds), but ensures the renderer works in any environment, even minimal ones like Docker scratch images or embedded systems without font support.
§Rendering
Rendering is decoupled from any specific imaging or graphics backend.
Instead, DrawingContext offers a draw method that invokes a
user-provided callback for each pixel, giving its (x, y) coordinate and color.
§Usage
A minimal setup requires:
- A
DrawingContext(can be reused across frames or content with the same settings), - A
Segmentsobject, which holds the segmented input text to render.
§Example
The examples/example.rs showcasing how the image crate may be used to render very obscure
characters onto a canvas.
use hieroglyph::{DrawingContext, Segments};
use image::{Pixel, Rgba, RgbaImage};
fn main() {
let name = "🅱 Jäne H🅱oe Bib 🦆 🇩🇪 🗕 🗗 🗙 𓁹‿𓁹 ♛";
let segments = Segments::new(name);
let mut ctx = DrawingContext::new();
ctx.rgb(255, 255, 255);
ctx.font_size(50.0);
let mut canvas = RgbaImage::new(ctx.width(&segments), 55);
ctx.draw(&segments, |(x, y), rgba| {
let color = Rgba(rgba);
let Ok(x) = x.try_into() else { return };
let Ok(y) = y.try_into() else { return };
let Some(pixel) = canvas.get_pixel_checked(x, y) else {
return;
};
let mut pixel = pixel.clone();
pixel.blend(&color);
canvas.put_pixel(x, y, pixel);
});
canvas.save("examples/example.png").unwrap();
}§Note
Line breaks (\n) are currently not supported.
Modules§
- fonts
- This module contains all the fonts included in
hieroglyph.
Structs§
- Drawing
Context - Context for drawing on arbitrary pixel buffers.
- Drawing
Context Builder - A builder to configure a new
DrawingContext. - Emoji
Segment EmojiSegmentrepresents a single emoji from the input string.- Segments
- Iterator over grapheme clusters and text segments of a string.
- Text
Segment TextSegmentholds a reference to a snippet of the input string.