pub struct TextShapingCache { /* private fields */ }Implementations§
Source§impl TextShapingCache
impl TextShapingCache
pub fn new() -> Self
Sourcepub fn memory_report(&self) -> TextCacheMemoryReport
pub fn memory_report(&self) -> TextCacheMemoryReport
Approximate per-stage heap-byte breakdown.
Sourcepub fn begin_generation(&mut self)
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.
Sourcepub fn use_old_layout(
old_constraints: &UnifiedConstraints,
new_constraints: &UnifiedConstraints,
old_content: &[InlineContent],
new_content: &[InlineContent],
) -> bool
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 layoutnew_constraints: The constraints for the new layout requestold_content: The content used for the cached layoutnew_content: The new content to layout
§Returns
trueif the old layout can be reused (only rendering changed)falseif a new layout is needed (layout-affecting params changed)
Source§impl TextShapingCache
impl TextShapingCache
Sourcepub 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>
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 rawInlineContentto be laid out.style_overrides- Character-level style changes.flow_chain- An ordered slice ofLayoutFragmentdefining 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 lookupsloaded_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.
Sourcepub 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>
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).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TextShapingCache
impl RefUnwindSafe for TextShapingCache
impl Send for TextShapingCache
impl Sync for TextShapingCache
impl Unpin for TextShapingCache
impl UnsafeUnpin for TextShapingCache
impl UnwindSafe for TextShapingCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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