Parley Rich Text Layout Engine
repository·main·Indexed 20 days ago
https://github.com/linebender/parleyA rich text layout engine for computing glyph positioning, line breaking, and text editing utilities. Parley utilizes HarfRust for text shaping and includes a suite of crates: attributed_text for managing styled text, Fontique for font enumeration and fallback, Parlance for typed text property representations, and parley_data for Unicode character properties via a compact CodePointTrie. It integrates with ICU4X for internationalization and text analysis.
What's inside Parley
- Parley is a library providing an API for implementing rich text layout. It handles the computation of x/y coordinates for each glyph in a string of text, including tasks such as determining glyph size, line breaking, and bidirectional (bidi) resolution. It also includes utilities for text selection and editing.
Overview of Parley
mainParley is a library providing an API for implementing rich text layout. It utilizes HarfRust as its backend for text shaping.Overview of Attributed Text
mainAttributed Text is a Rust crate designed for working with attributed text. It provides tools to manage text that carries metadata or styling attributes.
Features
std: Enabled by default. Currently unused but provided for forward compatibility.
Overview of Parley Engine
mainParley Engine provides low-level APIs for implementing text layout. It is designed for developers who need to build text rendering or layout systems from the ground up.Overview of Fontique
mainFontique is a library designed for font enumeration and font fallback. It allows developers to discover available fonts on a system and manage fallback logic when a specific font is unavailable.Use the Noto Color Emoji Subset
mainThe
noto_color_emojiassets folder provides a small subset of Noto Color Emoji to keep repository size manageable. This subset includes common emojis such as ✅, 👀, 🎉, 🤠, and ✌️.For rendering, the subset is provided in two formats:
- COLR format: Located in
NotoColorEmoji-Subset. - CBTF format: Located in
NotoColorEmoji-CBTF-Subset.
Both formats are supported by Vello.
- COLR format: Located in
Use Parlance for fundamental text property types
mainParlance is a lightweight,no_std-friendly vocabulary layer designed to provide small, typed representations of common text properties. It is intended to be shared across style systems, text layout engines, and font tooling. It provides typed handling for concepts such as weights, widths, OpenType tags, and language tags.What is the Itemization stage in Parley?
mainItemization is a text layout stage that breaks a paragraph into runs suitable for shaping. During this stage, the system:
- Segments text into runs based on style and properties.
- Selects appropriate fonts for each run.
- Maps each character to its nominal glyph identifier.
This prepares the text for the subsequent Shaping stage by ensuring each character is associated with the correct font and initial glyph ID.
What is the Shaping stage in Parley?
mainShaping is the stage that applies font, script, and language-specific processing rules to the itemized text. It transforms glyph runs using:
- Substitutions: Replacing nominal glyph IDs with specific glyph forms (e.g., providing appropriate Arabic cursive joining forms).
- Positioning adjustments: Calculating precise glyph placement.
- Advance widths: Computing the horizontal distance (advance) each glyph occupies.
The output of this stage is a set of shaped glyph identifiers and their corresponding advance widths, ready for rendering.
Use parley_data for Unicode character properties
mainThe
parley_datacrate provides the Unicode data required for Parley's text analysis and shaping pipeline. It uses aCompositePropsstructure backed by a compactCodePointTrie. This allows the engine to perform a single lookup to retrieve multiple character properties simultaneously, including:- Script
- General category
- Grapheme cluster break
- Bidi class
- Various emoji-related flags
Extensions to the piet text API in Parley
mainWhile Parley is built to expose the
piettext API, it proposes several extensions to provide more advanced typography features than the standardpietimplementation currently offers:- Advanced Text Attributes: Support for OpenType feature selectors and variation axes settings.
- Enhanced Hit-Testing: Support for selection affinity regarding the bounds of a selection, allowing for more sophisticated selection APIs beyond simple Unicode scalar offsets.
- Layout Customization (Planned): Potential support for user-specified letter, word, and line spacing, as well as customizable decorations (custom offsets, sizes, and colors for underlines and strikeouts).
How line breaking and reordering work in Parley
mainParley's final layout stage involves two key processes to handle complex text:
- Line Breaking: The engine performs line breaking based on boundary analysis (identifying where breaks are allowed).
- Reordering: Once lines are broken, the runs within each line are reordered using the Unicode bidirectional algorithm. This ensures that right-to-left (RTL) runs are correctly reversed and bidirectional runs are placed in the proper visual order.
The result is a sequence of glyphs where each glyph has a fully specified position, byte offset, and ID, correctly representing the visual intent of the text regardless of the underlying character directionality.