Skip to main content

Module shape

Module shape 

Source
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§

ShapedLine
A line of shaped text.
ShapedText
A block of shaped text with full layout information.
ShapedWord
A shaped word with positioning information.
TextHole
Represents a “hole” in the text layout where text won’t flow.
TextShapingOptions
Options for text shaping and layout

Enums§

TextAlign
Horizontal text alignment options
TextDirection
Text direction for bidirectional text support

Functions§

layout_to_ops
Convert a UnifiedLayout to PDF operations.
layout_to_ops_with_offset
Convert a UnifiedLayout to PDF operations with position offset.