Skip to main content

Module cache

Module cache 

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

  1. Logical AnalysisInlineContentLogicalItem
  2. BiDi ReorderingLogicalItemVisualItem
  3. ShapingVisualItemShapedItem
  4. Text Orientation — vertical writing-mode transforms
  5. Flow / Positioning — line breaking + final PositionedItem placement

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§

BidiLevel
BreakCursor
CachedLineBreaks
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.
ContentIndex
A stable, logical pointer to an item within the original InlineContent array.
CursorBoundsError
Error returned when cursor movement hits a boundary
FlowLayout
Represents the final layout distributed across multiple fragments.
FontChainKey
Key for caching font chains - based only on CSS properties, not text content
FontContext
Bundles all font-related state that can be shared across layout passes.
FontHash
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.
FontManager
FontSelector
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
GraphemeClusterId
A stable, logical identifier for a grapheme cluster.
HyphenationBreak
Represents a single valid hyphenation point within a word.
InitialLetter
InlineBorderInfo
Border information for inline elements (display: inline, inline-block)
InlineBreak
InlineImage
InlineShape
InlineSpace
IntrinsicTextSizes
Inline-axis intrinsic contributions derived from shaped text, without running the line-breaking stage of the pipeline.
LayoutFontMetrics
Layout-specific font metrics extracted from FontMetrics Contains only the metrics needed for text layout and rendering
LayoutFragment
Defines a single area for layout, with its own shape and properties.
LayoutKey
Key for the final layout stage.
LineConstraints
Line constraints with multi-segment support
LineSegment
LoadedFonts
A map of pre-loaded fonts, keyed by FontId (from rust-fontconfig)
LogicalItemsKey
Key for caching the conversion from InlineContent to LogicalItems.
MeasuredImage
MeasuredShape
OverflowInfo
Stores information about content that exceeded the available layout space.
PartialStyleProperties
PerItemShapedEntry
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
PositionedItem
Rect
ShapeConstraints
ShapedCluster
A group of glyphs that corresponds to one or more source characters (a cluster).
ShapedGlyph
A single, shaped glyph with its essential metrics.
ShapedItemsKey
Key for caching the shaping stage.
Size
Stroke
StyleOverride
StyleProperties
Style properties with vertical text support
StyledRun
TextCacheMemoryReport
Approximate heap bytes retained by a TextShapingCache.
TextDecoration
TextRunInfo
TextShapingCache
UnifiedConstraints
Unified constraints combining all layout features
UnifiedLayout
UnifiedLine
Intermediate structure carrying information from the line breaker to the positioner.
VerticalMetrics
VisualItem
VisualItemsKey
Key for caching the Bidi reordering stage.
VisualRun

Enums§

AvailableSpace
Available space for layout, similar to Taffy’s AvailableSpace.
BidiDirection
BreakType
CharacterClass
ClearType
FontChainKeyOrRef
Either a FontChainKey (resolved via fontconfig) or a direct FontRef hash.
FontOrRef
Enum that wraps either a fontconfig-resolved font (T) or a direct FontRef.
FontStack
Font stack that can be either a list of font selectors (resolved via fontconfig) or a direct FontRef (bypasses fontconfig entirely).
FontStyle
FontVariantCaps
FontVariantEastAsian
FontVariantLigatures
FontVariantNumeric
GlyphKind
The kind of a glyph, used to distinguish characters from layout-inserted items.
GlyphOrientation
GlyphSource
Hyphens
Controls whether hyphenation is allowed to create soft wrap opportunities.
ImageSource
IncrementalRelayoutResult
Result of an incremental relayout attempt.
InitialLetterAlign
Alignment mode for initial letters, controlling which alignment points are used to size and position the letter relative to the root inline box.
InlineContent
JustifyContent
LayoutError
LineBreakStrictness
LineHeight
CSS line-height value.
LogicalItem
ObjectFit
OverflowBehavior
OverflowWrap
CSS overflow-wrap (aka word-wrap) property.
PathSegment
SegmentAlignment
Defines how text should be aligned when a line contains multiple disjoint segments.
ShapeBoundary
ShapeDefinition
ShapedItem
Spacing
TextAlign
TextBoundary
Text boundary types for cursor movement
TextCombineUpright
TextOrientation
TextTransform
TextWrap
UnicodeBidi
CSS unicode-bidi property values relevant to layout. When Plaintext, the bidi algorithm uses P2/P3 heuristics to auto-detect paragraph direction from text content, instead of the HL1 override from the CSS direction property.
VerticalAlign
WhiteSpaceMode
WordBreak
WritingMode

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_separator which 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
ShapedGlyphVec
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 union feature of smallvec packs the inline buffer and the heap pointer into the same bytes, so sizeof stays sizeof(ShapedGlyph) + 2*usize regardless of inline/heap state.