Skip to main content

TextShapingCache

Struct TextShapingCache 

Source
pub struct TextShapingCache { /* private fields */ }

Implementations§

Source§

impl TextShapingCache

Source

pub fn new() -> Self

Source

pub fn memory_report(&self) -> TextCacheMemoryReport

Approximate per-stage heap-byte breakdown.

Source

pub fn begin_generation(&mut self)

Call at the start of each layout pass. Evicts per-item shaped entries not accessed in the previous generation to prevent unbounded growth.

Source

pub fn use_old_layout( old_constraints: &UnifiedConstraints, new_constraints: &UnifiedConstraints, old_content: &[InlineContent], new_content: &[InlineContent], ) -> bool

Check if we can reuse an old layout based on layout-affecting parameters.

This function compares only the parameters that affect glyph positions, not rendering-only parameters like color or text-decoration.

§Parameters
  • old_constraints: The constraints used for the cached layout
  • new_constraints: The constraints for the new layout request
  • old_content: The content used for the cached layout
  • new_content: The new content to layout
§Returns
  • true if the old layout can be reused (only rendering changed)
  • false if a new layout is needed (layout-affecting params changed)
Source§

impl TextShapingCache

Source

pub fn layout_flow<T: ParsedFontTrait>( &mut self, content: &[InlineContent], style_overrides: &[StyleOverride], flow_chain: &[LayoutFragment], font_chain_cache: &HashMap<FontChainKey, FontFallbackChain>, fc_cache: &FcFontCache, loaded_fonts: &LoadedFonts<T>, debug_messages: &mut Option<Vec<LayoutDebugMessage>>, ) -> Result<FlowLayout, LayoutError>

New top-level entry point for flowing layout across multiple regions.

This function orchestrates the entire layout pipeline, but instead of fitting content into a single set of constraints, it flows the content through an ordered sequence of LayoutFragments.

§CSS Inline Layout Module Level 3: Pipeline Implementation

This implements the inline formatting context with 5 stages:

§Stage 1: Logical Analysis (InlineContent -> LogicalItem)

\u2705 IMPLEMENTED: Parses raw content into logical units

  • Handles text runs, inline-blocks, replaced elements
  • Applies style overrides at character level
  • Implements \u00a7 2.2: Content size contribution calculation
§Stage 2: BiDi Reordering (LogicalItem -> VisualItem)

\u2705 IMPLEMENTED: Uses CSS ‘direction’ property per CSS Writing Modes

  • Reorders items for right-to-left text (Arabic, Hebrew)
  • Respects containing block direction (not auto-detection)
  • Conforms to Unicode BiDi Algorithm (UAX #9)
§Stage 3: Shaping (VisualItem -> ShapedItem)

\u2705 IMPLEMENTED: Converts text to glyphs

  • Uses HarfBuzz for OpenType shaping
  • Handles ligatures, kerning, contextual forms
  • Caches shaped results for performance
§Stage 4: Text Orientation Transformations

\u26a0\ufe0f PARTIAL: Applies text-orientation for vertical text

  • Uses constraints from first fragment only
  • \u274c TODO: Should re-orient if fragments have different writing modes
§Stage 5: Flow Loop (ShapedItem -> PositionedItem)

\u2705 IMPLEMENTED: Breaks lines and positions content

  • Calls perform_fragment_layout for each fragment
  • Uses BreakCursor to flow content across fragments
  • Implements \u00a7 5: Line breaking and hyphenation
§Missing Features from CSS Inline-3:
  • \u00a7 3.3: initial-letter (drop caps)
  • \u00a7 4: vertical-align (only baseline supported)
  • \u00a7 6: text-box-trim (leading trim)
  • \u00a7 7: inline-sizing (aspect-ratio for inline-blocks)
§Arguments
  • content - The raw InlineContent to be laid out.
  • style_overrides - Character-level style changes.
  • flow_chain - An ordered slice of LayoutFragment defining the regions (e.g., columns, pages) that the content should flow through.
  • font_chain_cache - Pre-resolved font chains (from FontManager.font_chain_cache)
  • fc_cache - The fontconfig cache for font lookups
  • loaded_fonts - Pre-loaded fonts, keyed by FontId
§Returns

A FlowLayout struct containing the positioned items for each fragment that was filled, and any content that did not fit in the final fragment.

§Panics

Panics if bidi reordering of the logical items fails (an internal invariant).

§Errors

Returns a LayoutError if text flow layout fails.

Source

pub fn measure_intrinsic_widths<T: ParsedFontTrait>( &mut self, content: &[InlineContent], style_overrides: &[StyleOverride], constraints: &UnifiedConstraints, font_chain_cache: &HashMap<FontChainKey, FontFallbackChain>, fc_cache: &FcFontCache, loaded_fonts: &LoadedFonts<T>, debug_messages: &mut Option<Vec<LayoutDebugMessage>>, ) -> Result<IntrinsicTextSizes, LayoutError>

Runs stages 1–4 of the layout pipeline (logical analysis, BiDi, shaping, text orientation) and derives min/max-content widths by scanning the resulting ShapedItems directly — without running stage 5’s line-breaking BreakCursor loop.

Used by calculate_ifc_root_intrinsic_sizes to avoid the 24% CPU spent cloning ShapedClusters inside BreakCursor::peek_next_unit on every sizing pass. Since stages 1–3 hit the same per_item_shaped cache as layout_flow, a subsequent layout_flow call for the same content at a real container width is a pure cache hit for the shaping work.

The item walk uses the same break-opportunity predicate that the BreakCursor would — min-content accumulates advances between break opportunities and tracks the maximum; max-content is the sum of all advances (as if the flow were laid out on a single infinitely-wide line).

§Panics

Panics if bidi reordering of the logical items fails (an internal invariant).

§Errors

Returns a LayoutError if measuring intrinsic widths fails.

Trait Implementations§

Source§

impl Debug for TextShapingCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TextShapingCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.