graphitepdf-textkit 0.2.0

Minimal text shaping and text block primitives for GraphitePDF.
Documentation

Overview

graphitepdf-textkit is the dedicated text subsystem for GraphitePDF.


Scope

graphitepdf-textkit contains:

  • authoring types such as TextSpan, TextBlock, AttributedString, and TextAttributes
  • container and geometry types such as TextRect and TextContainer
  • resolved output such as TextRun, TextFragment, LineFragment, and TextLayout
  • TextEngine and TextEngineConfig for line-breaking, bidi, justification, and font substitution behavior

Installation

cargo add graphitepdf-textkit

API Summary

Category Items
Authoring TextSpan, TextBlock, AttributedString, AttributeRun, TextRange
Attributes TextAttributes, TextDecoration, TextDecorationKind, TextDirection, Script
Containers TextRect, TextContainer
Layout output TextRun, TextFragment, LineFragment, TextLayout
Engine TextEngine, TextEngineConfig, BidiMode, LineBreaking, Justification, FontSubstitution

Example

use graphitepdf_font::FontStore;
use graphitepdf_textkit::{
    TextBlock, TextContainer, TextEngine, TextEngineConfig, TextRect, TextSpan,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let block = TextBlock::from(TextSpan::new("GraphitePDF text layout")?);
    let container = TextContainer::new(TextRect::from_values(0.0, 0.0, 180.0, 60.0))?;
    let engine = TextEngine::new(TextEngineConfig::default());
    let font_store = FontStore::new();

    let layout = engine.layout_text_block(&block, &container, Some(&font_store))?;
    assert!(!layout.lines().is_empty());
    Ok(())
}

Design Principles

  • keep text shaping and line layout centralized in one crate
  • make font fallback, bidi, and line-breaking behavior configurable
  • expose text results as structured data rather than ad hoc strings
  • keep the text subsystem reusable for higher-level layout and rendering crates

Role In GraphitePDF

This crate is the canonical text engine that feeds layout and ultimately the rendering pipeline.


License

MIT