3 releases

0.7.2 May 1, 2024
0.7.1 Mar 30, 2024
0.7.0 Jan 13, 2024

#244 in Images

Download history 65/week @ 2024-01-25 65/week @ 2024-02-01 159/week @ 2024-02-08 416/week @ 2024-02-15 445/week @ 2024-02-22 311/week @ 2024-02-29 437/week @ 2024-03-07 392/week @ 2024-03-14 382/week @ 2024-03-21 684/week @ 2024-03-28 322/week @ 2024-04-04 299/week @ 2024-04-11 380/week @ 2024-04-18 658/week @ 2024-04-25 477/week @ 2024-05-02 460/week @ 2024-05-09

2,039 downloads per month
Used in 10 crates (3 directly)


4.5K SLoC

You are probably looking for the real cosmic-text crate.

Floem depends on cosmic-text changes that haven't been upstreamed. To make Floem publishable on crates.io, all its dependencies have to be published there - hence this unofficial crate.



This library provides advanced text handling in a generic way. It provides abstractions for shaping, font discovery, font fallback, layout, rasterization, and editing. Shaping utilizes rustybuzz, font discovery utilizes fontdb, and the rasterization is optional and utilizes swash. The other features are developed internal to this library.

It is recommended that you start by creating a FontSystem, after which you can create a Buffer, provide it with some text, and then inspect the layout it produces. At this point, you can use the SwashCache to rasterize glyphs into either images or pixels.

use floem_cosmic_text::{Attrs, Color, FontSystem, SwashCache, Buffer, Metrics};

// A FontSystem provides access to detected system fonts, create one per application
let mut font_system = FontSystem::new();

// A SwashCache stores rasterized glyphs, create one per application
let mut swash_cache = SwashCache::new();

// Text metrics indicate the font size and line height of a buffer
let metrics = Metrics::new(14.0, 20.0);

// A Buffer provides shaping and layout for a UTF-8 string, create one per text widget
let mut buffer = Buffer::new(&mut font_system, metrics);

// Borrow buffer together with the font system for more convenient method calls
let mut buffer = buffer.borrow_with(&mut font_system);

// Set a size for the text buffer, in pixels
buffer.set_size(80.0, 25.0);

// Attributes indicate what font to choose
let attrs = Attrs::new();

// Add some text!
buffer.set_text("Hello, Rust! 🦀\n", attrs);

// Perform shaping as desired

// Inspect the output runs
for run in buffer.layout_runs() {
    for glyph in run.glyphs.iter() {
        println!("{:#?}", glyph);

// Create a default text color
let text_color = Color::rgb(0xFF, 0xFF, 0xFF);

// Draw the buffer (for performance, instead use SwashCache directly)
buffer.draw(&mut swash_cache, text_color, |x, y, w, h, color| {
    // Fill in your code here for drawing rectangles


~308K SLoC