Parley Rich Text Layout Engine

repository·main·Indexed 20 days ago

https://github.com/linebender/parley

A 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.

Tokens
45.7K
Snippets
173
Records
225
Agent score
51%

What's inside Parley

  1. Overview of Parley rich text layout

    main
    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.
  2. Use the Noto Color Emoji Subset

    main

    The noto_color_emoji assets 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:

    1. COLR format: Located in NotoColorEmoji-Subset.
    2. CBTF format: Located in NotoColorEmoji-CBTF-Subset.

    Both formats are supported by Vello.

  3. Use Parlance for fundamental text property types

    main
    Parlance 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.
  4. What is the Itemization stage in Parley?

    main

    Itemization is a text layout stage that breaks a paragraph into runs suitable for shaping. During this stage, the system:

    1. Segments text into runs based on style and properties.
    2. Selects appropriate fonts for each run.
    3. 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.

  5. What is the Shaping stage in Parley?

    main

    Shaping 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.

  6. Use parley_data for Unicode character properties

    main

    The parley_data crate provides the Unicode data required for Parley's text analysis and shaping pipeline. It uses a CompositeProps structure backed by a compact CodePointTrie. 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
  7. Extensions to the piet text API in Parley

    main

    While Parley is built to expose the piet text API, it proposes several extensions to provide more advanced typography features than the standard piet implementation 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).
  8. How line breaking and reordering work in Parley

    main

    Parley's final layout stage involves two key processes to handle complex text:

    1. Line Breaking: The engine performs line breaking based on boundary analysis (identifying where breaks are allowed).
    2. 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.