azul-text-layout
General crate for text layout / text shaping
Example
use ;
let text = "hello";
let font_size = 14.0; // px
let font = include_bytes!;
let font_index = 0; // only for fonts with font collections
let font_metrics = get_font_metrics_freetype;
let words = split_text_into_words;
let scaled_words = words_to_scaled_words;
let total_width = scaled_words.items.iter.map.sum;
Full text layout
use ;
use ;
use ResolvedTextLayoutOptions;
// set all options of the text
let text = "hello";
let font_size = 14.0; // px
let font_bytes = include_bytes!;
let font_index = 0; // only for fonts with font collections
let text_layout_options = ResolvedTextLayoutOptions ;
// Cache the font metrics of the given font (baseline, height, etc.)
let font_metrics = get_font_metrics_freetype;
// "Hello World" => ["Hello", "World"]
let words = split_text_into_words;
// "Hello" @ 14px => Size { width: 50px, height: 14px }
let scaled_words = words_to_scaled_words;
// Calculate the origin of the word relative to the line
let word_positions = position_words;
// Calculate the origin of the line relative to (0, 0)
let mut inline_text_layout = word_positions_to_inline_text_layout;
// Align the line horizontally
inline_text_layout.align_children_horizontal;
// Calculate the glyph positons (line_offset + word_offset + glyph_offset)
let layouted_glyphs = get_layouted_glyphs;
println!; // get infos about word offset, line breaking, etc.
println!; // get the final glyph positions relative to the origin
License: MIT