Expand description
Core types and layout pipeline for the text/inline formatting context.
This module defines the central data structures (UnifiedConstraints,
LayoutCache, FontManager, UnifiedLayout, etc.) and implements the
5-stage inline layout pipeline:
- Logical Analysis —
InlineContent→LogicalItem - BiDi Reordering —
LogicalItem→VisualItem - Shaping —
VisualItem→ShapedItem - Text Orientation — vertical writing-mode transforms
- Flow / Positioning — line breaking + final
PositionedItemplacement
The module also contains cursor movement helpers, caching infrastructure
(per-item and monolithic), and font management (FontContext, FontManager,
LoadedFonts). Integration with the box layout solver lives in
solver3/fc.rs.
Re-exports§
pub use crate::font_traits::ParsedFontTrait;pub use crate::font_traits::ShallowClone;
Structs§
- Bidi
Level - Break
Cursor - Cached
Line Breaks - Cached line break boundaries from a previous layout pass. Enables incremental relayout: when a word changes width, we can check if it still fits on the same line without re-running the full line-breaking algorithm.
- Content
Index - A stable, logical pointer to an item within the original
InlineContentarray. - Cursor
Bounds Error - Error returned when cursor movement hits a boundary
- Flow
Layout - Represents the final layout distributed across multiple fragments.
- Font
Chain Key - Key for caching font chains - based only on CSS properties, not text content
- Font
Context - Bundles all font-related state that can be shared across layout passes.
- Font
Hash - A reference to a font for rendering, identified by its hash. This hash corresponds to ParsedFont::hash and is used to look up the actual font data in the renderer’s font cache.
- Font
Manager - Font
Selector - A selector for loading fonts from the font cache. Used by FontManager to query fontconfig and load font files.
- Glyph
- Enhanced glyph with all features
- Grapheme
Cluster Id - A stable, logical identifier for a grapheme cluster.
- Hyphenation
Break - Represents a single valid hyphenation point within a word.
- Initial
Letter - Inline
Border Info - Border information for inline elements (display: inline, inline-block)
- Inline
Break - Inline
Image - Inline
Shape - Inline
Space - Intrinsic
Text Sizes - Inline-axis intrinsic contributions derived from shaped text, without running the line-breaking stage of the pipeline.
- Layout
Font Metrics - Layout-specific font metrics extracted from FontMetrics Contains only the metrics needed for text layout and rendering
- Layout
Fragment - Defines a single area for layout, with its own shape and properties.
- Layout
Key - Key for the final layout stage.
- Line
Constraints - Line constraints with multi-segment support
- Line
Segment - Loaded
Fonts - A map of pre-loaded fonts, keyed by FontId (from rust-fontconfig)
- Logical
Items Key - Key for caching the conversion from
InlineContenttoLogicalItems. - Measured
Image - Measured
Shape - Overflow
Info - Stores information about content that exceeded the available layout space.
- Partial
Style Properties - PerItem
Shaped Entry - Cached shaped result for a single visual item (or coalesced group). Enables per-item cache hits when only one word changes in a paragraph.
- Point
- Positioned
Item - Rect
- Shape
Constraints - Shaped
Cluster - A group of glyphs that corresponds to one or more source characters (a cluster).
- Shaped
Glyph - A single, shaped glyph with its essential metrics.
- Shaped
Items Key - Key for caching the shaping stage.
- Size
- Stroke
- Style
Override - Style
Properties - Style properties with vertical text support
- Styled
Run - Text
Cache Memory Report - Approximate heap bytes retained by a
TextShapingCache. - Text
Decoration - Text
RunInfo - Text
Shaping Cache - Unified
Constraints - Unified constraints combining all layout features
- Unified
Layout - Unified
Line - Intermediate structure carrying information from the line breaker to the positioner.
- Vertical
Metrics - Visual
Item - Visual
Items Key - Key for caching the Bidi reordering stage.
- Visual
Run
Enums§
- Available
Space - Available space for layout, similar to Taffy’s AvailableSpace.
- Bidi
Direction - Break
Type - Character
Class - Clear
Type - Font
Chain KeyOr Ref - Either a FontChainKey (resolved via fontconfig) or a direct FontRef hash.
- Font
OrRef - Enum that wraps either a fontconfig-resolved font (T) or a direct FontRef.
- Font
Stack - Font stack that can be either a list of font selectors (resolved via fontconfig) or a direct FontRef (bypasses fontconfig entirely).
- Font
Style - Font
Variant Caps - Font
Variant East Asian - Font
Variant Ligatures - Font
Variant Numeric - Glyph
Kind - The kind of a glyph, used to distinguish characters from layout-inserted items.
- Glyph
Orientation - Glyph
Source - Hyphens
- Controls whether hyphenation is allowed to create soft wrap opportunities.
- Image
Source - Incremental
Relayout Result - Result of an incremental relayout attempt.
- Initial
Letter Align - Alignment mode for initial letters, controlling which alignment points are used to size and position the letter relative to the root inline box.
- Inline
Content - Justify
Content - Layout
Error - Line
Break Strictness - Line
Height - CSS
line-heightvalue. - Logical
Item - Object
Fit - Overflow
Behavior - Overflow
Wrap - CSS
overflow-wrap(akaword-wrap) property. - Path
Segment - Segment
Alignment - Defines how text should be aligned when a line contains multiple disjoint segments.
- Shape
Boundary - Shape
Definition - Shaped
Item - Spacing
- Text
Align - Text
Boundary - Text boundary types for cursor movement
- Text
Combine Upright - Text
Orientation - Text
Transform - Text
Wrap - Unicode
Bidi - CSS
unicode-bidiproperty values relevant to layout. WhenPlaintext, the bidi algorithm uses P2/P3 heuristics to auto-detect paragraph direction from text content, instead of the HL1 override from the CSSdirectionproperty. - Vertical
Align - White
Space Mode - Word
Break - Writing
Mode
Functions§
- break_
one_ line - Breaks a single line of items to fit within the given geometric constraints, handling multi-segment lines and hyphenation. Break a single line from the current cursor position.
- create_
logical_ items - extract_
line_ breaks - Extract line break boundaries from a positioned items list.
- find_
all_ hyphenation_ breaks - A “word” is defined as a sequence of one or more adjacent ShapedClusters.
- get_
base_ direction_ from_ logical - get_
item_ measure - Helper to get the primary measure (width or height) of a shaped item.
- get_
item_ vertical_ metrics - Gets the ascent (distance from baseline to top) and descent (distance from baseline to bottom) for a single item, incorporating half-leading from line-height. +spec:display-property:fd42a9 - line-height affects line box contribution, not inline box size
- get_
item_ vertical_ metrics_ approx - Approximate version of get_item_vertical_metrics for use without constraints (e.g. bounds()). Uses 80/20 ascent/descent ratio as fallback for empty-glyph strut case.
- is_
collapsible_ whitespace - Returns true if the item is collapsible whitespace per CSS Text 3 §4.1.2 Phase II.
This is used for stripping leading/trailing whitespace at line edges —
distinct from
is_word_separatorwhich is for word-spacing per §7.1. - is_
cursive_ script_ cluster - Returns true if the cluster’s first character belongs to a cursive script (Arabic, Syriac, Mongolian, N’Ko, Mandaic, Phags Pa, Hanifi Rohingya) per CSS Text 3 Appendix D. These scripts should not have letter-spacing applied.
- is_
word_ separator - is_
zero_ width_ space - Helper to identify if an item is a zero-width space (U+200B), which provides a soft wrap opportunity with no visible width. Used in scripts like Thai, Lao, and Khmer that don’t use spaces between words.
- justify_
kashida_ and_ rebuild - Rebuilds a line of items, inserting Kashida glyphs for justification.
- perform_
fragment_ layout - Performs layout for a single fragment, consuming items from a
BreakCursor. - position_
one_ line - Positions a single line of items, handling alignment and justification within segments.
- reorder_
logical_ items - shape_
visual_ items - shape_
visual_ items_ with_ per_ item_ cache - Shape visual items into ShapedItems using pre-loaded fonts.
- try_
incremental_ relayout - Attempt incremental relayout given old metrics and new per-item advance widths.
Type Aliases§
- CacheId
- FourCc
- Shaped
Glyph Vec - Glyph storage for a single shaped cluster. Inline one glyph (the
common case for Latin text), spill to heap for ligatures / combining
marks / multi-glyph clusters. The
unionfeature of smallvec packs the inline buffer and the heap pointer into the same bytes, so sizeof stayssizeof(ShapedGlyph) + 2*usizeregardless of inline/heap state.