pub fn shape_visual_items_with_per_item_cache<T: ParsedFontTrait>(
visual_items: &[VisualItem],
per_item_cache: &mut HashMap<u64, Arc<PerItemShapedEntry>>,
per_item_accessed: &mut HashSet<u64>,
font_chain_cache: &HashMap<FontChainKey, FontFallbackChain>,
fc_cache: &FcFontCache,
loaded_fonts: &LoadedFonts<T>,
debug_messages: &mut Option<Vec<LayoutDebugMessage>>,
) -> Result<Vec<ShapedItem>, LayoutError>Expand description
Shape visual items into ShapedItems using pre-loaded fonts.
This function does NOT load any fonts - all fonts must be pre-loaded and passed in.
If a required font is not in loaded_fonts, the text will be skipped with a warning.
Optimization: Inline Run Coalescing
// +spec:display-property:9c6d59 - text shaping not broken across inline box boundaries when no effective formatting change
// +spec:display-property:cf8917 - text shaping not broken across inline box boundaries
When consecutive text VisualItems share the same layout-affecting properties
(font, size, spacing, etc.) but differ only in rendering properties (color,
background), they are coalesced into a single shaping call. This dramatically
reduces the number of font.shape_text() invocations for syntax-highlighted
code where hundreds of <span> elements use the same monospace font but
different colors. After shaping, the original per-span styles are restored
to each ShapedCluster based on byte-range mapping.
Shape visual items with per-item caching. For each item (or coalesced group),
compute a cache key from (text, bidi_level, script, style_layout_hash). On cache
hit, reuse the previously shaped clusters. On miss, shape and store.
This is the incremental shaping path: when one word changes in a paragraph, only that word’s item misses the per-item cache; all other items hit.