Expand description
Text shaping, to position text manually Text shaping and measurement
This module provides functionality for measuring and shaping text, allowing for complex text layout with precise positioning, line breaks, and text flow around “holes” (like images or other non-text content).
§Overview
The text shaping pipeline converts raw text + font into positioned glyphs:
Text + Font + Options
↓
UnifiedLayout (from azul-layout text3 engine)
↓
Vec<Op> (PDF operations)§Example
ⓘ
use printpdf::*;
// Load a font
let font_bytes = std::fs::read("my_font.ttf")?;
let font = ParsedFont::from_bytes(&font_bytes, 0)?;
// Shape text
let options = TextShapingOptions::new(Pt(12.0))
.with_max_width(Pt(200.0))
.with_align(TextAlign::Left);
let layout = shape_text("Hello, World!", &font, &options)?;
// Convert to PDF operations
let ops = layout_to_ops(&layout, page_height, &font_id, Color::black());Structs§
- Shaped
Line - A line of shaped text.
- Shaped
Text - A block of shaped text with full layout information.
- Shaped
Word - A shaped word with positioning information.
- Text
Hole - Represents a “hole” in the text layout where text won’t flow.
- Text
Shaping Options - Options for text shaping and layout
Enums§
- Text
Align - Horizontal text alignment options
- Text
Direction - Text direction for bidirectional text support
Functions§
- layout_
to_ ops - Convert a
UnifiedLayoutto PDF operations. - layout_
to_ ops_ with_ offset - Convert a
UnifiedLayoutto PDF operations with position offset.